PowerShell – Restart Computer

PowerShell restart Computer

Using Restart-Computer cmdlet

Use the Restart-Computer cmdlet to restart the local/remote computer. The syntax of this command is given below.

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

After executing the above command, you can observe that the computer is restarted instantly. Let’s see another example:

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

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:

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.

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

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.

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:

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.

Use Shutdown Command for Remote Computers

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.

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.

Example 2: Restart multiple computers

Use Restart-Computer with parameter ComputerName to restart remote computers. You can use comma to separater multiple computers.

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.

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.

Was this post helpful?

Related Posts

  • Check if Service is running in PowerShell
    05 January

    Check if Service is Running in PowerShell

    Table of ContentsUsing Get-Service CmdletUse Get-Service Cmdlet with if-else BlockUsing Get-SPServiceApplication Cmdlet Using Get-Service Cmdlet Use Get-Service with the Where-Object cmdlet to check if a particular service is running on our local machine. [crayon-63b6cf2d510dc112466289/] [crayon-63b6cf2d510e3192920831/] If you need to put if condition, then head over to this section . We used the Get-Service cmdlet to […]

  • Run reg file in PowerShell
    05 January

    Run .reg File Using PowerShell

    Table of ContentsUsing Invoke-Item CmdletUsing Start-Process CmdletUsing iex OperatorUsing . OperatorUsing reg import Command Using Invoke-Item Cmdlet Use the Invoke-Item cmdlet to run the .reg file using PowerShell. [crayon-63b6cf2d51725095711594/] For the above command, Invoke-Item performed its default action, which means it allowed us to execute a .reg file. We can also use it to run […]

  • Get Current Directory in PowerShell
    05 January

    Get Current Directory in PowerShell

    Table of ContentsUsing Get-Location CmdletUsing $pwd CommandUsing Resolve-Path Cmdlet [ Relative Path]Using Split-Path Cmdlet [ Get Parent working directory]Using System.Environment ClassUsing $PSScriptRoot Variable [Get Current directory of PowerShell Script ] Using Get-Location Cmdlet Use the Get-Location cmdlet to get the path of the current working directory in PowerShell. [crayon-63b6cf2d51cf0047319211/] [crayon-63b6cf2d51cf5154099462/] As we can see above, […]

  • Check if Variable is null in PowerShell
    04 January

    PowerShell – Check If Variable Is Null

    Table of ContentsUsing $null VariableUsing Conditional StatementUsing IsNullorEmpty() MethodUsing IsNullOrWhiteSpace() MethodUsing Null-Coalescing Operators Using $null Variable Use the $null variable with the -eq parameter to check whether a variable is equal to $null. [crayon-63b6cf2d4a136033187983/] [crayon-63b6cf2d4a13c998570269/] The above code returned a Boolean value True which means a variable is equal to null. What is null? null […]

  • PowerShell get filename for Path
    03 January

    PowerShell – Get Filename from Path

    Table of ContentsPowerShell – Get Filename From Specified PathUsing Split-Path CmdletUsing Get-Item CmdletUsing Get-ChildItem CmdletUsing GetFileName() MethodGetting Multiple File NamesWith ExtensionsWithout Extension PowerShell – Get Filename From Specified Path The location of a file on a system can be determined by its path. In PowerShell, there are several ways to get filename from path. Firstly, […]

  • Count files in folder in PowerShell
    01 January

    PowerShell – Count Files in Folders

    Table of ContentsCount Files in Folders in PowerShellCount Files in multiple Folders in PowerShellCount Files in Folders and Subfolders in PowerShellCount only folders inside folder in PowerShellCount Files by Extension in Folder in PowerShell Count Files in Folders in PowerShell We can use the Measure-Object cmdlet in different ways to meet our project requirements. However, […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.