Homepage 5 How-to Articles 5 How to Shutdown Computers via Powershell Remotely

How to Shutdown Computers via Powershell Remotely

Manage remote endpoints, deploy software and patches with a robust cloud-based Action1 RMM solution. Sign up to Action1 to use RMM tools free forever on up to 100 endpoints.

June 25, 2020

It is logical that most people will always use graphic windows and a mouse to complete work on the computer, this is correct since it is simpler and faster, but there are a number of cases when you, as an advanced user or a system administrator, are simply obliged to be able to perform all tasks without a GUI interface. PowerShell has been recognized as one of the core Windows remote management tools. It will be useful, for example, to massively shut down computers on a list. PowerShell performs the shutdown remote computers in bulk without enabling remote shutdown capability (which can pose a major security risk).

How to Shutdown Single Computer via PowerShell

In order to turn off the computer, let’s turn to a modern tool, namely PowerShell. We open it in administrator mode, we will be interested in the Stop-Computer cmdlet. If you simply enter it in a shell on the local computer, then you will begin shutting down.

Shutdown Remote Computers via PowerShell

Now let’s see the help for this cmdlet, for this enter the following command:

Get-Help Stop-Computer

Shutdown Remote Computers. Get Help Stop Computer

Shutdown Remote Computers Using PowerShell cmdlet

The Stop-Computer cmdlet has the -ComputerName switch, through which you can specify a list of systems that require shutdown. I have two remote computers with Windows 10, w10-cl02 and w10-cl03. Let’s turn them off, enter the command:

Stop-Computer -ComputerName w10-cl02, w10-cl03

If someone is currently working on remote computers, you will get an error.

To solve this, you can add the -Force key, which will do a forced shutdown:

Stop-Computer -ComputerName w10-cl02, w10-cl03 -Force

If you need to perform a shutdown on behalf of a specific account, then you can use the -Credential switch:

Stop-Computer -ComputerName w10-cl02, w10-cl03 -Credential root\sem -Force

root is the name of the domain, and sem is the username.

In the Windows credential prompt, specify a password.

A situation may arise that you or your colleagues may prepare a test file with a list of computers that need to be turned off. Stop-Computer will easily cope with this task. I put on the C:\drive the computers.txt file, and then I execute the commands.

$s = Get-Content -Path C:\computers.txt

$c = Get-Credential root\sem

Stop-Computer -ComputerName $s -Force -Credential $c

Shutdown Remote Computers. Shutdown a list of computers

Also, you can shutdown multiple remote computers from AD domain. The following script is suitable for this.

  • $room=Get-ADOrganizationalUnit -LDAPFilter '(name=*)' -SearchBase 'OU=Workstations,DC=sid-666,DC=com' -SearchScope OneLevel | Select-Object DistinguishedName | Out-GridView -PassThru -Title 'Select Computers OU to shutdown all Computers in that OU'
  • $comp=(Get-ADComputer -SearchBase $room.distinguishedname -Filter *).Name
  • Foreach ($c in $comp)
  • {Stop-Computer -ComputerName $c -ErrorAction SilentlyContinue -Force -Verbose}

Time-delayed Computer Shutdown via PowerShell

And so, how to turn off the computer after a certain time, since you can easily have such a scenario. To resolve the issue over time, there is the Start-Sleep cmdlet.

Start-Sleep -Seconds 60; Stop-Computer -ComputerName w10-cl02, w10-cl03 -Force

Time-delayed Computer Shutdown via PowerShell

As a result of the command, work will be completed on two remote computers. Or you can like this with a list of computers in a text file.

  • $s = Get-Content -Path C:\computers.txt
  • $c = Get-Credential root\sem
  • Start-Sleep -Seconds 60; Stop-Computer -ComputerName $s -Force -Credential $c

Note: Remember that you have to adapt line 1 to suit your OU structure.

How to Shutdown a Computer via a WMI Query

Also using the command line or PowerShell, you can execute the command using WMI to shut down the computer. To do this, enter the command:

(Get-WmiObject Win32_OperatingSystem -EnableAllPrivileges).Win32Shutdown(1)

Shutdown a Computer via a WMI

As a result, you will have the correct shutdown in your Windows system, you can also do a forced shutdown, to do this:

(Get-WmiObject Win32_OperatingSystem -EnableAllPrivileges).Win32Shutdown(5)

Consider Using Action1 to Shutdown Remote Computers if:

  • You need to perform an action on multiple computers simultaneously.
  • You have remote employees with computers not connected to your corporate network.

Action1 RMM is a cloud-based solution for patch management, software deployment, remote desktop, IT asset inventory, and remote endpoint management.

Related Articles

How To Delete User Profiles Remotely with PowerShell

When a user logs onto the computer for the first time (not via the network to access shared folders or printers), Windows creates a user profile. Among its contents are the NTUSER.DAT file (user profile settings), user-specific folders (My Documents, Desktop, etc.),...

How to Uninstall Programs With Standard Windows Tools

UThis tutorial for new users details where to add and remove Windows 10 programs, the quickest way to get to this Control Panel component, and more information on how to properly uninstall Windows 10 programs and applications from your computer. In fact, when compared...

How to Upgrade Windows 10 Build from the Command Line

The setup.exe installer in the Windows 10 distribution has a fairly large set of command-line options that may be of interest to the administrator for automating and managing updating the build (version / build) of Windows 10 on users computers using SCCM and other...

About Action1 RMM

Action1 is a cloud-based IT solution for remote monitoring and management, patching, and remote support.

Try Action1 Free RMM on 100 endpoints with no functionality limitations or expiration!

0 Comments

Submit a Comment

Your email address will not be published.