WSUS Deprecation: Your Next Move in Patch Management

This Wednesday | 12 PM EST / 11 AM CET

Action1 5 How-to Articles 5 How to Shutdown Remote Computers via PowerShell 

How to Shutdown Remote Computers via PowerShell 

June 25, 2020

By Peter Barnett

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 the PowerShell shutdown command. 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 to stop computer via PowerShell :

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 PowerShell Script to Shutdown Computer

And so, how to shutdown remote computer with PowerShell 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 shutdown or reboot computer PowerShell on multiple computers simultaneously.
  • You have remote employees with computers not connected to your corporate network.

Action1 is a cloud-based solution for remote monitoring and management that encompasses tools for remote IT management. Some of the features include patch management system, software deployment, remote access, IT asset inventory, and remote endpoint management.

See What You Can Do with Action1

 

Join our weekly LIVE demo “Patch Management That Just Works with Action1” to learn more

about Action1 features and use cases for your IT needs.

 

spiceworks logo
getapp logo review
software advice review
trustradius
g2 review
spiceworks logo

Related Posts