Export (0) Print
Expand All
2 out of 2 rated this helpful - Rate this topic

Restart-Computer

Updated: October 17, 2013

Applies To: Windows PowerShell 4.0

Restart-Computer

Restarts ("reboots") the operating system on local and remote computers.

Syntax

Parameter Set: DefaultSet
Restart-Computer [[-ComputerName] <String[]> ] [[-Credential] <PSCredential> ] [-DcomAuthentication <AuthenticationLevel> ] [-Delay <Int16> ] [-For <WaitForServiceTypes> ] [-Force] [-Impersonation <ImpersonationLevel> ] [-Protocol <String> ] [-Timeout <Int32> ] [-Wait] [-WsmanAuthentication <String> ] [-Confirm] [-WhatIf] [ <CommonParameters>]

Parameter Set: AsJobSet
Restart-Computer [[-ComputerName] <String[]> ] [[-Credential] <PSCredential> ] [-AsJob] [-DcomAuthentication <AuthenticationLevel> ] [-Force] [-Impersonation <ImpersonationLevel> ] [-ThrottleLimit <Int32> ] [-Confirm] [-WhatIf] [ <CommonParameters>]




Detailed Description

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 concurrently, and to force an immediate restart.

Beginning in Windows PowerShell 3.0, you can wait for the restart to complete before running the next command, specify a waiting timeout 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

Runs the command as a background job.

Note: To use this parameter, the local and remote computers must be configured for remoting and, on Windows Vista and later versions of Windows, you must open Windows PowerShell with the "Run as administrator" option. For more information, see about_Remote_Requirements (http://go.microsoft.com/fwlink/?LinkID=135187).

When you use 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 completes. 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.


For more information about Windows PowerShell background jobs, see about_Jobs (http://go.microsoft.com/fwlink/?LinkID=113251) and about_Remote_Jobs (http://go.microsoft.com/fwlink/?LinkID=135184).


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ComputerName<String[]>

Specifies one or more remote 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.


Aliases

CN,__SERVER,Server,IPAddress

Required?

false

Position?

1

Default Value

Local computer

Accept Pipeline Input?

True (ByValue, ByPropertyName)

Accept Wildcard Characters?

false

-Credential<PSCredential>

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 from the Get-Credential cmdlet.


Aliases

none

Required?

false

Position?

2

Default Value

Current user

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Delay<Int16>

Determines how often 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 with the Wait and For parameters.

This parameter is introduced in Windows PowerShell 3.0.


Aliases

none

Required?

false

Position?

named

Default Value

5

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-For<WaitForServiceTypes>

Waits until the specified service or feature is available after the computer is restarted. Specify one of the valid values. This parameter is valid only with the Wait parameter.

Valid values 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 is introduced in Windows PowerShell 3.0.


Aliases

none

Required?

false

Position?

named

Default Value

Default

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Force

Forces an immediate restart of the computers.


Aliases

f

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Impersonation<ImpersonationLevel>

Specifies the impersonation level to use when calling WMI. (Restart-Computer uses WMI.) The default value is "Impersonate".\

Valid values 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.


Aliases

none

Required?

false

Position?

named

Default Value

Impersonate

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-ThrottleLimit<Int32>

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.


Aliases

none

Required?

false

Position?

named

Default Value

32

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Timeout<Int32>

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

The Timeout parameter is valid only with the Wait parameter.

This parameter is introduced in Windows PowerShell 3.0.


Aliases

TimeoutSec

Required?

false

Position?

named

Default Value

-1

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Wait

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 processing when the restart is complete.

By default, the Wait parameter waits indefinitely for the computers to restart, but you can use the Timeout parameter 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 the Wait parameter on the local computer, but it waits for the remote computers to restart.

This parameter is introduced in Windows PowerShell 3.0.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-DcomAuthentication<AuthenticationLevel>

Specifies the authentication level that is used for the WMI connection. (Restart-Computer uses WMI.) The default value is Packet.

Valid values 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.

For more information about the values of this parameter, see "AuthenticationLevel Enumeration" in MSDN at http://go.microsoft.com/fwlink/?LinkID=235229.

This parameter is introduced in Windows PowerShell 3.0.


Aliases

Authentication

Required?

false

Position?

named

Default Value

Packet

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Protocol<String>

Specifies which protocol to use to restart the computers. Valid values are WSMan and DCOM. The default value is DCOM.

This parameter is introduced in Windows PowerShell 3.0.


Aliases

none

Required?

false

Position?

named

Default Value

DCOM

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WsmanAuthentication<String>

Specifies the mechanism that is used to authenticate the user's credentials when using the WSMan protocol.

Valid values are Basic, CredSSP, Default, Digest, Kerberos, and Negotiate. The default value is Default. For more information about the values of this parameter, see "AuthenticationMechanism Enumeration" in MSDN at http://go.microsoft.com/fwlink/?LinkID=235230.

Caution: Credential Security Service Provider (CredSSP) authentication, in which the user's 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 is introduced in Windows PowerShell 3.0.


Aliases

none

Required?

false

Position?

named

Default Value

Default

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

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


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.String

    You can pipe computer names to Restart-Computer.

    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

The output type is the type of the objects that the cmdlet emits.

  • None or System.Management.Automation.RemotingJob

    When you use the AsJob parameter, the cmdlet returns a job object. Otherwise, it does not generate any output.


Notes

  • This cmdlet uses the Win32Shutdown method of the WMI WIN32_OperatingSystem class.

  • In Windows PowerShell 2.0, the AsJob parameter does not work reliably when you are restarting/stopping remote computers. In Windows PowerShell 3.0, the implementation is changed to resolve this problem.

Examples

-------------------------- EXAMPLE 1 --------------------------

This command restarts the local computer.


PS C:\> Restart-Computer

-------------------------- EXAMPLE 2 --------------------------

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


PS C:\> Restart-Computer -ComputerName Server01, Server02, localhost

-------------------------- EXAMPLE 3 --------------------------

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


 

The first command uses the AsJob parameter to run the command as a background job. The command saves the resulting job object in the $j variable.


PS C:\> $j = Restart-Computer -ComputerName Server01, Server02 -AsJob

 

The second command uses a pipeline operator to send the job object in $j to the Receive-Job cmdlet, which gets the job results. The command saves the results in the $Results variable.


PS C:\> $Results = $j | Receive-Job

 

The third command displays the result saved in the $Results variable.

Because the AsJob parameter creates the job on the local computer and automatically returns the results to the local computer, you can run the Receive-Job command as a local command.


PS C:\> $Results

-------------------------- EXAMPLE 4 --------------------------

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


PS C:\> Restart-Computer -ComputerName Server01 -Impersonation Anonymous -Authentication PacketIntegrity

-------------------------- EXAMPLE 5 --------------------------

These commands force an immediate restart of all of the computers in Domain01.


 

The first command uses the Get-Content cmdlet to get a list of computers in the domain from the Domain01.txt file. It saves the list in the $s variable.


PS C:\> $s = Get-Content Domain01.txt

 

The second command gets the credentials of a domain administrator and saves them in the $c variable.


PS C:\> $c = Get-Credential Domain01\Admin01

 

The third command restarts the computers. 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.


PS C:\> Restart-Computer -ComputerName $s -Force -ThrottleLimit 10 -Credential $c

-------------------------- EXAMPLE 6 --------------------------

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 continuing.

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.


PS C:\> Restart-Computer -ComputerName Server01 -Wait -For PowerShell -Timeout 300 -Delay 2

-------------------------- EXAMPLE 7 --------------------------

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.


PS C:\> Restart-Computer -ComputerName Server01 -Protocol WSMan -WSManAuthentication Kerberos

Related topics



Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.