- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to restart a remote system using PowerShell?
To restart the remote computer, you need to use the Restart-Computer command provided by the computer name. For example,
Restart-Computer -ComputerName Test1-Win2k12
The above command will restart computer Test1-Win2k12 automatically and if you have multiple remote computers to restart then you can provide multiple computers separated with comma (,).For example,
Restart-Computer -ComputerName Test1-Win2k12, Test2-Win2k12
Restart signal will be sent to both the computers at a time in the above example.
You can also use the Pipeline to restart remote computers. For example,
"Test1-Win2k12","Test2-Win2k12" | Restart-Computer -Verbose
OR
(Get-Content C:\Servers.txt) | Restart-Computer -Verbose
Few servers have dependencies on the other servers so main servers need to restart first. For example, AD and Exchange servers. If you are giving both the servers in the same command line then both servers will reboot at the same time and this is what we don't need it. To overcome this solution, you need to pass each server one at a time, write a few steps for server post-reboot checklist, and then move on to the next server. You can add servers to the array or text file and then pass a single value through foreach loop and the steps for the post-reboot checklist and move on to the next server.
People often confuse with the - Wait parameter in the Restart-Computer cmdlet that - Wait parameter will reboot one server at a time after the server post-reboot checklist completes but - Wait parameter only performs the three major checklists like WinRM, WMI and PowerShell connectivity check on the remote computer for each computer specified in the cmdlet after server comes up but it can't hold the execution of servers reboot.
Restart-Computer shoots reboot command on all the computers and - Wait parameter does the checks on each computer the specified tests and even if the remote computer failed in checks, servers will reboot.
When anyone is logged on to the remote server(s), PowerShell failed to restart the remote server and throws the below error message.
PS C:\Users\Administrator> Restart-Computer test1-win2k12 –Verbose
VERBOSE: Performing the operation "Enable the Remote shutdown access rights and restart the computer." on target "test1-win2k12". Restart-Computer : Failed to restart the computer test1-win2k12 with the following error message: The system shutdown cannot be initiated because there are other users logged on to thecomputer. At line:1 char:1+ Restart-Computer test1-win2k12 -Verbose+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (test1-win2k12:String) [Restart- Computer], InvalidOperationException + FullyQualifiedErrorId : RestartcomputerFailed,Microsoft.PowerShell.Commands.RestartComputerCommand
To restart the computer forcefully, you need to use -Force parameter.
Restart-Computer Test1-Win2k12 -Force
- Related Articles
- How to test remote computer connectivity using PowerShell?
- How to restart the Azure VM using Azure CLI in PowerShell?
- How to check if remote ports are open using PowerShell?
- How to remove connected remote desktop user sessions using PowerShell?
- How to get all the processes on remote computers using PowerShell?
- How to get connected remote desktop users on computers using PowerShell?
- How to use –Wait parameter in Restart-Computer cmdlet in PowerShell?
- How to use -For parameter in Restart-Computer cmdlet in PowerShell?
- How to use –Timeout parameter in Restart-Computer cmdlet in PowerShell?
- How to get services on remote computers with PowerShell?
- How to open a port in the Windows Operating System using PowerShell?
- How to copy files/folders to the remote location in the PowerShell?
- How to block ports on the Windows Operating System using PowerShell?
- How to find the MAC address of the system using PowerShell?
- How to eject the USB device from the system using PowerShell?
