Table of Contents
Using Restart-Computer
cmdlet
Use the Restart-Computer
cmdlet to restart the local/remote computer. The syntax of this command is given below.
1 2 3 |
Restart-Computer [parameters] |
The Restart-Computer command has some parameters that we can use based on our requirements. You can find parameter names and their description below:
Parameter | Description |
---|---|
ComputerName |
It is used to enter the system’s name that needs restarted. |
Force |
It is used to execute the command forcefully. |
Wait |
It blocks the prompt messages until the timeout. This parameter is not applicable for restarting local computer. |
Timeout |
It is used to specify the time for an action to be performed. |
Delay |
It is used to delay the restart process. A five-second delay is used if the Delay parameter is not specified. |
WhatIf |
It is used to display a message showing what would happen if we run Restart-Computer. |
NOTE: This
Restart-Computer
cmdlet is available on the Windows platform only.
Use Restart-Computer
cmdlet for Local Computers
1 2 3 |
Restart-Computer |
After executing the above command, you can observe that the computer is restarted instantly. Let’s see another example:
1 2 3 |
Restart-Computer -WhatIf |
1 2 3 |
What if: Performing the operation "Enable the Local shutdown access rights and restart the computer." on target "localhost (DESKTOP-ULR90KV)." |
Here, we can observe that we got the above message after running the Restart-Computer -WhatIf
command on the PowerShell console window. Remember that this cmdlet does not run Restart-Computer
. However, this example illustrates what would happen if Restart-Computer
were run.
Use Restart-Computer
cmdlet for Remote Computer
1 2 3 |
Restart-Computer -ComputerName DELL-computer_01, DELL-computer_02, localhost |
In the above PowerShell script, the Restart-Computer
cmdlet has been used to restart multiple remote computers. Here, the -ComputerName
parameter accepted DELL-computer_01
and DELL-computer_02
as names of remote computers that we want to restart. Have a look at another example:
1 2 3 |
Restart-Computer -ComputerName computer_01 -Force |
In this example, we connected to a remote computer called computer_01
. Then, using the -Force
parameter, the computer is restarted instantly without any default confirmation.
Using Shutdown
Command
Use the Shutdown
command to shut down or restart local/remove computers. The syntax of the Shutdown
command can be found below.
1 2 3 |
Shutdown [parameters] |
A Shutdown
command can be used with the following set of parameters.
Parameter | Description |
---|---|
/s |
It shuts down the system using PowerShell. |
/r |
It is used to restart the computer. |
/h |
It is used to set the computer to hibernate mode. |
/l |
It is used to log off the computer. |
/t |
It is used to specify the timeout period before shutdown. |
/m |
It is used to specify the target computer’s name. |
Use Shutdown
Command for Local Computers
1 2 3 |
Shutdown /r |
The above command will restart the local PC/Laptop after showing a pop-up with the message Window will be restarted in less than a minute
. However, if you want to shut down your computer after some specific time, specify the timer, as shown in the following example.
1 2 3 |
Shutdown /r /t 60 |
Above, /t
was used to specify a timeout, as discussed above. When this command is executed, the computer will shut down after a delay of 60 seconds. And if you want to shut down your computer, replace /r
with /s
as shown below:
1 2 3 |
Shutdown [/s] |
It will take less than a minute for your computer to shut down once the above command has been executed. We can also set a timer for shutting down our computer as we did for restarting it.
1 2 3 |
Shutdown /s /t 60 |
Use Shutdown
Command for Remote Computers
1 2 3 |
shutdown /r /m \\DELL-PC01 /t 60 |
Here, the /m
parameter was used to specify the target computer’s name. In the above example, DELL-PC01
was the name of a remote computer (you can replace it with your remote computer’s name) which we wanted to shut down after 60 seconds. Similarly, we can shut down the remote computer using the following command.
1 2 3 |
shutdown /s /m \\DELL-PC01 /t 60 |
NOTE: Using PowerShell as an administrator is recommended for Shutdown command.
Examples
Here are the practical examples to restart computer with various parameters.
Example 1: Restart local computer
Use Restart-Computer
without any parameter to restart local computer.
1 2 3 |
Restart-Computer |
Example 2: Restart multiple computers
Use Restart-Computer
with parameter ComputerName
to restart remote computers. You can use comma to separater multiple computers.
1 2 3 |
Restart-Computer -ComputerName Computer01, Computer02, localhost |
Example 3: Restart remote computer with wait, timeout, delay and for parameters.
Here is command to restart computer and waits for 10 mins to PowerShell to become available on restated computer to process further.
1 2 3 |
Restart-Computer -ComputerName Computer01 -Wait -For PowerShell -Timeout 600 -Delay 5 |
Above command will restart computer named Computer01
. It will wait for restart to finish for 10 mins. Here, for
specifies that powershell can run commands on remote computer.
Delay
is used to query remote computer every 5 secs to check where remote computer is restarted or not.
That’s all about how to restart computer using PowerShell.