Stop-Computer
Stop-Computer [[-ComputerName] <String[]>] [[-Credential] <PSCredential>] [-AsJob] [-Confirm] [-DcomAuthentication{Default | None | Connect | Call | Packet | PacketIntegrity | PacketPrivacy | Unchanged}] [-Force] [-Impersonation{Default | Anonymous | Identify | Impersonate | Delegate}] [-Protocol {DCOM | WSMan}] [-ThrottleLimit <Int32>][-WhatIf] [-WsmanAuthentication {Default | Basic | Negotiate | CredSSP | Digest | Kerberos}] [<CommonParameters>]
The Stop-Computer cmdlet shuts down computers remotely. It can also shut down the local computer.
You can use the parameters of Stop-Computer to run the shutdown operations as a background job, to specify the authentication levels and alternate credentials, to limit the concurrent connections that are created to run the command, and to force an immediate shut down.
This cmdlet does not require Windows PowerShell remoting unless you use the AsJob parameter.
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 get the job results, use the Receive-Job cmdlet.
-ComputerName <String[]>
- Default value is None
- Accepts pipeline input ByPropertyName
Specifies the computers to stop. The default is the local computer.
Type the NETBIOS name, IP address, or fully qualified domain name of one or more computers in a comma-separated list. To specify the local computer, type the computer name 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 from the Get-Credential cmdlet.
-DcomAuthentication <AuthenticationLevel>
- Default value is None
- Accepts pipeline input False
Specifies the authentication level that this cmdlet uses with WMI. Stop-Computer uses WMI. The acceptable values for this parameter are:
- Default. Windows Authentication - None. No COM authentication - Connect. Connect-level COM authentication - Call. Call-level COM authentication - Packet . Packet-level COM authentication - PacketIntegrity. Packet Integrity-level COM authentication - PacketPrivacy. Packet Privacy-level COM authentication - Unchanged. Same as the previous command
The default value is Packet.
-Force [<SwitchParameter>]
- Default value is False
- Accepts pipeline input False
Forces an immediate shut down of the computers.
-Impersonation <ImpersonationLevel>
- Default value is None
- Accepts pipeline input False
Specifies the impersonation level to use when this cmdlet calls WMI. Stop-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.
-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 this cmdlet uses the WSMan protocol. The acceptable values for this parameter are:
- Basic
- CredSSP
- Default
- Digest
- Kerberos
- 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
NoneOutputs
None or System.Management.Automation.RemotingJobExamples
-
Shut down the local computer:
PS C:\> Stop-Computer
This command shuts down the local computer.
-
Shut down two remote computers and the local computer:
PS C:\> Stop-Computer -ComputerName "Server01", "Server02", "localhost"
This command stops two remote computers, Server01 and Server02, and the local computer, identified as localhost.
-
Shut down remote computers as a background job:
PS C:\> $j = Stop-Computer -ComputerName "Server01", "Server02" -AsJob PS C:\> $results = $j | Receive-Job PS C:\> $results
These commands run Stop-Computer as a background job on two remote computers, and then get the results.
The first command specifies the AsJob parameter to run the command as a background job. The command saves the resulting job object in the $j variable.
The second command uses a pipeline operator to send the job object in $j to Receive-Job , which gets the job results. The command saves the results in the $results variable.
The third command displays the result saved 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.
-
Shut down a remote computer:
PS C:\> Stop-Computer -CompupterName "Server01" -Impersonation anonymous -Authentication PacketIntegrity
This command stops the Server01 remote computer. The command uses customized impersonation and authentication settings.
-
These commands force an immediate shut down of all of the computers
in Domain01:
PS C:\> $s = Get-Content Domain01.txt PS C:\> $c = Get-Credential domain01\admin01 PS C:\> Stop-Computer -ComputerName $s -Force -ThrottleLimit 10 -Credential $c
The first command gets a list of computers in the domain, and then stores them in the $s variable.
The second command gets the credentials of a domain administrator, and then stores them in the $c variable.
The third command shuts down the computers. It uses ComputerName parameter to submit the list of computers in the $s variable, the Force parameter to force an immediate shutdown, 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.
Additional Notes
This cmdlet uses the Win32Shutdown method of the Win32_OperatingSystem * WMI 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.
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