Skip to content
PowerShell Commands

Restart-Computer

Restart-Computer [[-ComputerName] <String[]>] [[-Credential] <PSCredential>] [-AsJob] [-Confirm][-DcomAuthentication {Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}][-Force] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}] [-ThrottleLimit <Int32>][-WhatIf] [<CommonParameters>]
Restart-Computer [[-ComputerName] <String[]>] [[-Credential] <PSCredential>] [-Confirm] [-DcomAuthentication{Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}] [-Delay <Int16>] [-For{Wmi | WinRM | PowerShell}] [-Force] [-Impersonation {Default | Anonymous | Identify | Impersonate | Delegate}][-Protocol {DCOM | WSMan}] [-Timeout <Int32>] [-Wait] [-WhatIf] [-WsmanAuthentication {Default | Basic | Negotiate| CredSSP | Digest | Kerberos}] [<CommonParameters>]

The Restart-Computer cmdlet restarts the operating system on the local and remote computers.

You can use the parameters of Restart-Computer to run the restart operations as a background job, to specify the authentication levels and alternate credentials, to limit the operations that run at the same time, and to force an immediate restart.

Starting in Windows PowerShell 3.0, you can wait for the restart to complete before you run the next command, specify a waiting time-out and query interval, and wait for particular services to be available on the restarted computer. This feature makes it practical to use Restart-Computer in scripts and functions. You can also use the WSMan protocol to restart the computer, in case DCOM calls are blocked, such as by an enterprise firewall.

This cmdlet requires Windows PowerShell remoting only when you use the AsJob parameter in a command.

Parameters

-AsJob [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Indicates that this cmdlet runs as a background job.

To use this parameter, the local and remote computers must be configured for remoting and, on Windows Vista and later versions of the Windows operating system, you must open Windows PowerShell by using the Run as administrator option.

When you specify the AsJob parameter, the command immediately returns an object that represents the background job. You can continue to work in the session while the job finishes. The job is created on the local computer and the results from remote computers are automatically returned to the local computer. To manage the job, use the Job cmdlets. To get the job results, use the Receive-Job cmdlet.

-ComputerName <String[]>

  • Default value is None
  • Accepts pipeline input ByPropertyName

Specifies one or more computers. The default is the local computer.

Type the NETBIOS name, an IP address, or a fully qualified domain name of a remote computer. To specify the local computer, type the computer name, a dot (.), or localhost.

This parameter does not rely on Windows PowerShell remoting. You can use the ComputerName parameter even if your computer is not configured to run remote commands.

-Confirm [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Prompts you for confirmation before running the cmdlet.

-Credential <PSCredential>

  • Default value is None
  • Accepts pipeline input False

Specifies a user account that has permission to perform this action. The default is the current user.

Type a user name, such as User01 or Domain01\User01, or enter a PSCredential object, such as one generated by the Get-Credential cmdlet.

-DcomAuthentication <AuthenticationLevel>

  • Default value is None
  • Accepts pipeline input False

Specifies the authentication level that is used for the WMI connection. The acceptable values for this parameter are:

- Call. Call-level COM authentication - Connect. Connect-level COM authentication - Default. Windows Authentication - None. No COM authentication - Packet. Packet-level COM authentication - PacketIntegrity. Packet Integrity-level COM authentication - PacketPrivacy. Packet Privacy-level COM authentication - Unchanged. The authentication level is the same as the previous command

The default value is Packet.

This parameter was introduced in Windows PowerShell 3.0.

-Delay <Int16>

  • Default value is None
  • Accepts pipeline input False

Determines how often, in seconds, Windows PowerShell queries the service that is specified by the For parameter to determine whether it is available after the computer is restarted. Specify a delay between queries, in seconds. The default value is 5 seconds.

This parameter is valid only together with the Wait and For parameters.

This parameter was introduced in Windows PowerShell 3.0.

-For <WaitForServiceTypes>

  • Default value is None
  • Accepts pipeline input False

Specifies the behavior of Windows PowerShell as it waits for the specified service or feature to become available after the computer restarts. This parameter is valid only with the Wait parameter.

The acceptable values for this parameter are:

- Default. Waits for Windows PowerShell to restart. - PowerShell. Can run commands in a Windows PowerShell remote session on the computer. - WMI. Receives a reply to a Win32_ComputerSystem query for the computer. - WinRM. Can establish a remote session to the computer by using WS-Management.

This parameter was introduced in Windows PowerShell 3.0.

-Force [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Forces an immediate restart of the computers.

-Impersonation <ImpersonationLevel>

  • Default value is None
  • Accepts pipeline input False

Specifies the impersonation level that this cmdlet uses to call WMI. Restart-Computer uses WMI. The acceptable values for this parameter are:

-- Default. Default impersonation. - Anonymous. Hides the identity of the caller. - Identify. Allows objects to query the credentials of the caller. - Impersonate. Allows objects to use the credentials of the caller.

The default value is Impersonate.

-Protocol <String>

  • Default value is None
  • Accepts pipeline input False

Specifies which protocol to use to restart the computers. The acceptable values for this parameter are: WSMan and DCOM. The default value is DCOM.

This parameter was introduced in Windows PowerShell 3.0.

-ThrottleLimit <Int32>

  • Default value is None
  • Accepts pipeline input False

Specifies the maximum number of concurrent connections that can be established to run this command. If you omit this parameter or enter a value of 0, the default value, 32, is used.

The throttle limit applies only to the current command, not to the session or to the computer.

-Timeout <Int32>

  • Default value is None
  • Accepts pipeline input False

Specifies the duration of the wait, in seconds. When the time-out elapses, Restart-Computer returns the command prompt, even if the computers are not restarted. The default value, -1, represents an indefinite time-out.

The Timeout parameter is valid only with the Wait parameter.

This parameter was introduced in Windows PowerShell 3.0.

-Wait [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Indicates that this cmdlet suppresses the Windows PowerShell prompt and blocks the pipeline until all of the computers have restarted. You can use this parameter in a script to restart computers and then continue to process when the restart is finished.

By default, Wait waits indefinitely for the computers to restart, but you can use Timeout to adjust the timing and the For and Delay parameters to wait for particular services to be available on the restarted computers.

The Wait parameter is not valid when you are restarting the local computer. If the value of the ComputerName parameter contains the names of remote computers and the local computer, Restart-Computer generates a non-terminating error for Wait on the local computer, but it waits for the remote computers to restart.

This parameter was introduced in Windows PowerShell 3.0.

-WhatIf [<SwitchParameter>]

  • Default value is False
  • Accepts pipeline input False

Shows what would happen if the cmdlet runs. The cmdlet is not run.

-WsmanAuthentication <String>

  • Default value is None
  • Accepts pipeline input False

Specifies the mechanism that is used to authenticate the user credentials when you use the WSMan protocol.

The acceptable values for this parameter are: Basic, CredSSP, Default, Digest, Kerberos, and Negotiate. The default value is Default.

Caution: Credential Security Service Provider (CredSSP) authentication, in which the user credentials are passed to a remote computer to be authenticated, is designed for commands that require authentication on more than one resource, such as accessing a remote network share. This mechanism increases the security risk of the remote operation. If the remote computer is compromised, the credentials that are passed to it can be used to control the network session.

This parameter was introduced in Windows PowerShell 3.0.

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug,ErrorAction, ErrorVariable, WarningAction, WarningVariable,OutBuffer, PipelineVariable, and OutVariable.

Inputs
System.String
You can pipe computer names to this cmdlet.. In Windows PowerShell 2.0, the ComputerName parameter takes input from the pipeline only by property name. In Windows PowerShell 3.0, the ComputerName parameter takes input from the pipeline by value.
Outputs
None, System.Management.Automation.RemotingJob
This cmdlet returns a job object, if you specify the AsJob parameter. Otherwise, it does not generate any output.
Examples
  1. Restart the local computer:
    PS C:\> Restart-Computer
    

    This command restarts the local computer.

  2. Restart several computers including the local computer:
    PS C:\> Restart-Computer -ComputerName "Server01", "Server02", "localhost"
    

    This command restarts two remote computers, Server01 and Server02, and the local computer, identified as localhost.

  3. Restart computers as a background job:
    1. The first command uses the *AsJob* parameter to run the command as a background job:
      PS C:\> $j = Restart-Computer -ComputerName "Server01", "Server02" -AsJob
      

      The command stores the resulting job object in the $j variable.

    2. The second command uses a pipeline operator to send the job object in $j to the Receive-Job cmdlet, which gets the job results:
      PS C:\> $Results = $j | Receive-Job
      

      The command stores the results in the $Results variable.

    3. The third command displays the result stores in the $Results variable.Because *AsJob* creates the job on the local computer and automatically returns the results to the local computer, you can run **Receive-Job** as a local command:
      PS C:\> $Results
      

      These commands run a Restart-Computer command as a background job on two remote computers, and then get the results.

  4. Restart a remote computer:
    PS C:\> Restart-Computer -ComputerName "Server01" -Impersonation Anonymous -Authentication PacketIntegrity
    

    This command restarts the Server01 remote computer. The command uses customized impersonation and authentication settings.

  5. Force restart of all computers in a domain:
    1. The first command uses the Get-Content cmdlet to get a list of computers in the domain from the Domain01.txt file:
      PS C:\> $s = Get-Content Domain01.txt
      

      It stores the list in the $s variable.

    2. The second command gets the credentials of a domain administrator and stores them in the $c variable:
      PS C:\> $c = Get-Credential Domain01\Admin01
      
    3. The third command restarts the computers:
      PS C:\> Restart-Computer -ComputerName $s -Force -ThrottleLimit 10 -Credential $c
      

      It uses the *ComputerName* parameter to submit the list of computers in the $s variable, the *Force* parameter to force an immediate restart, and the *Credential* parameter to submit the credentials saved in the $c variable. It also uses the *ThrottleLimit* parameter to limit the command to 10 concurrent connections.This example forces an immediate restart of all of the computers in Domain01.

  6. Restart a remote computer and wait:
    PS C:\> Restart-Computer -ComputerName "Server01" -Wait -For PowerShell -Timeout 300 -Delay 2
    

    This command restarts the Server01 remote computer and then waits up to 5 minutes (300 seconds) for Windows PowerShell to be available on the restarted computer before it continues.

    The command uses the Wait , For , and Timeout parameters to specify the conditions of the wait. It uses the Delay parameter to reduce the interval between queries to the remote computer that determine whether it is restarted.

  7. Restart a computer by using WSMan:
    PS C:\> Restart-Computer -ComputerName "Server01" -Protocol WSMan -WSManAuthentication Kerberos
    

    This command restarts the Server01 remote computer by using the WSMan protocol, instead of DCOM, which is the default. It also uses Kerberos authentication to determine whether the current user has permission to restart the remote computer.

    These settings are designed for enterprises in which DCOM-based restarts fail because DCOM is blocked, such as by a firewall.

Additional Notes
 This cmdlet uses the Win32Shutdown method of the WMI WIN32_OperatingSystem * class. In Windows PowerShell 2.0, 
 AsJob* does not work reliably when you are restarting/stopping remote computers. In Windows PowerShell 3.0, 
 the implementation is changed to resolve this problem.

This work is licensed under a Creative Commons Attribution 4.0 International. It is attributed to Microsoft Corporation and can be found here.

PowerShell Commands