In Windows PowerShell, you have two main commands for controlling shutdown and restart functions: Restart-Computer and Stop-Computer. Each command can manage both local and remote computers over a network, providing flexibility for single or multiple system management.
Restart Command: To reboot a Windows machine, use:
Restart-Computer -Force
Shutdown Command: For a full shutdown:
Stop-Computer
Table of Contents
Adjusting the Restart Delay
By default, a reboot starts in five seconds. Need a delay? Add the -Delay parameter to control timing:
Restart-Computer –Delay 60
Running Commands on Remote Computers
Using the -ComputerName parameter, you can specify one or multiple remote machines to restart or shutdown. Example for shutting down two remote servers:
Stop-Computer -ComputerName "mun-srv01", "mun-srv02"
Adding Credentials for Remote Access
To authenticate on a remote machine, store credentials and pass them with the command:
$Creds = Get-Credential Restart-Computer -ComputerName mun-srv01 -Credential $Creds
Note: Remote connections rely on WMI (Windows Management Instrumentation) or DCOM (Distributed Component Object Model). These must be enabled on the target machine; otherwise, access may be denied.
Using WSMan Protocol as an Alternative
If WMI isn’t configured, but Windows Remote Management (WinRM) is active, use the -Protocol parameter to switch to WSMan:
Restart-Computer -ComputerName wks-11222 -Protocol WSMan
Handling Active User Sessions
If other users are logged into the remote machine, attempting a reboot may trigger an error. To see active sessions:
qwinsta /server:wks-11222
To override, add -Force:
Restart-Computer -ComputerName wks-11222 -Force
Monitoring Reboot Status
To verify a remote machine restarts and becomes available for management, use the -Wait -For parameters:
Restart-Computer -ComputerName wks-11222 -Wait -For WinRM
You can also wait for specific services, such as Remote Desktop Service (RDP):
Restart-Computer -ComputerName wks-11222 -Wait -For TermService
Restarting Multiple Computers Simultaneously
In PowerShell 7.x, parallel command execution allows batch restarts. Example to restart multiple Windows Servers within an Active Directory Organizational Unit (OU):
$Computers = (Get-ADComputer -Filter 'operatingsystem -like "*Windows server*" -and enabled -eq "true"' -SearchBase "OU=Servers,DC=woshub,DC=com").Name $Computers | ForEach-Object -Parallel { Restart-Computer -ComputerName $_ -Force } -ThrottleLimit 3
Using these PowerShell commands, you’ll manage reboots and shutdowns efficiently, whether you’re handling one computer or an entire network.