PowerShell

How to use PowerShell to restart a Remote Windows computer

How to use PowerShell to restart a Remote Windows computer

Every now and then, most especially, a system administrator will need to restart a server or system. Usually, you can remotely connect to a system and restart/shutdown the system through the graphical user interface - PowerShell provides several methods for rebooting a computer remotely and we will outline the 6 known methods in this post.

Restart a Windows computer remotely using PowerShell

A prerequisite to these methods is to ensure that we can contact the remote systems and authenticate as necessary. And also, you need to verify that a remote system is not pending a reboot.

You'll need the following:

1] Restart a remote computer with Restart-Computer

This cmdlet is simple to use with flexible parameters. An additional prerequisite for the command to work is, ensure that WinRM is configured and allowed through the remote computer's Windows firewall and that WMI is allowed through the Windows firewall.

Restart-Computer -ComputerName $ComputerName -Force

To restart multiple computers in parallel, run the following command:

$ComputerArray | ForEach-Object -Parallel  Restart-Computer -ComputerName $_ -Force  -ThrottleLimit 3

2] Restart a remote computer with Invoke-CimMethod

The Invoke-CimMethod works by using a WIM method to reboot the remote system - although, not as flexible as the Restart-Computer cmdlet.

An additional prerequisite for the command to work is, ensure that WinRM is configured and allowed through the remote computer's Windows firewall.

Invoke-CimMethod -ComputerName $ComputerName -ClassName 'Win32_OperatingSystem' -MethodName 'Reboot'

3] Restart a remote computer with shutdown.exe

The shutdown.exe is the standard built-in executable that Windows offers to restart a system, and it's not a PowerShell command but offers a robust series of options.

An additional prerequisite for the command to work is, ensure that the remote computer has the Remote Registry service enabled and WMI allowed through the Windows firewall.

shutdown.exe /m \\remotecomputer /r /t 0

4] Restart a remote computer with PSExec.exe

One of the most used utilities within the Sysinternals toolkit, psexec.exe offers several unique abilities that make interacting with a remote system easy.

An additional prerequisite for the command to work is, ensure the SMB Service is running, file and printer sharing is enabled, simple file sharing is disabled and the admin$ administrative share is available.

psexec.exe -d -h \\remotecomputer "shutdown.exe /r /t 0 /f"

5] Restart a remote computer with RunDLL32.exe

The rundll32.exe offers a way to run certain methods against internal executables and Windows APIs, such as shell32.dll. There are two methods you can restart a system using this functionality but this method cannot be actually used remotely by itself, you can combine this with PowerShell via an Invoke-Command on a remote system.

Method 1:

Invoke-Command -ComputerName $ComputerName -ScriptBlock  & rundll32.exe user.exe ExitWindowsExec 

Method 2:

Invoke-Command -ComputerName $ComputerName -ScriptBlock  & rundll32.exe user.exe ExitWindowsExec 

6] Restart a remote computer with Taskkill.exe

Last but not the least, taskkill.exe is one other Windows utility that offers some functionality to restart Windows, though in a roundabout way. By ending the lsass.exe process, you will force a Windows restart.

taskkill.exe /S \\remotecomputer /IM lsass.exe /F

That's it on the 6 ways to use PowerShell to restart a remote computer!

How to change Mouse pointer and cursor size, color & scheme on Windows 10
The mouse pointer and cursor in Windows 10 are very important aspects of the operating system. This can be said for other operating systems as well, s...
Linux Oyunları Geliştirmek için Ücretsiz ve Açık Kaynaklı Oyun Motorları
Bu makale, Linux'ta 2D ve 3D oyunlar geliştirmek için kullanılabilecek ücretsiz ve açık kaynaklı oyun motorlarının bir listesini kapsayacaktır. Bu tür...
Linux Eğitimi için Tomb Raider'ın Gölgesi
Shadow of the Tomb Raider, Eidos Montreal tarafından yaratılan bir aksiyon-macera oyunu serisi olan Tomb Raider serisine eklenen on ikinci oyundur. Oy...