Stop-Computer
Stops (shuts down) local and remote computers.
Syntax
Stop-Computer
[-WsmanAuthentication <String>]
[[-ComputerName] <String[]>]
[[-Credential] <PSCredential>]
[-Force]
[-WhatIf]
[-Confirm]
[<CommonParameters>]
Description
The Stop-Computer
cmdlet shuts down the local computer and remote computers.
You can use the parameters of Stop-Computer
to specify the authentication levels and alternate
credentials, and to force an immediate shut down.
In PowerShell 7.1, Stop-Computer
was added for Linux and macOS. The parameters have no effect on
these platforms. The cmdlet is just calling the native command /sbin/shutdown
.
Examples
Example 1: Shut down the local computer
This example shuts down the local computer.
Stop-Computer -ComputerName localhost
Example 2: Shut down two remote computers and the local computer
This example stops two remote computers and the local computer.
Stop-Computer -ComputerName "Server01", "Server02", "localhost"
Stop-Computer
uses the ComputerName parameter to specify two remote computers and the local
computer. Each computer is shut down.
Example 3: Shut down remote computers as a background job
In this example, Stop-Computer
runs as a background job on two remote computers.
The background operator &
runs the Stop-Computer
command as a background job. For more
information, see
about_Operators.
$j = Stop-Computer -ComputerName "Server01", "Server02" &
$results = $j | Receive-Job
$results
Stop-Computer
uses the ComputerName parameter to specify two remote computers. The &
background operator runs the command as a background job. The job objects are stored in the $j
variable.
The job objects in the $j
variable are sent down the pipeline to Receive-Job
, which gets the job
results. The objects are stored in the $results
variable. The $results
variable displays the job
information in the PowerShell console.
Example 4: Shut down a remote computer
This example shuts down a remote computer using specified authentication.
Stop-Computer -ComputerName "Server01" -WsmanAuthentication Kerberos
Stop-Computer
uses the ComputerName parameter to specify the remote computer. The
WsmanAuthentication parameter specifies to use Kerberos to establish a remote connection.
Example 5: Shut down computers in a domain
In this example, the commands force an immediate shut down of all computers in a specified domain.
$s = Get-Content -Path ./Domain01.txt
$c = Get-Credential -Credential Domain01\Admin01
Stop-Computer -ComputerName $s -Force -Credential $c
Get-Content
uses the Path parameter to get a file in the current directory with the list of
domain computers. The objects are stored in the $s
variable.
Get-Credential
uses the Credential parameter to specify the credentials of a domain
administrator. The credentials are stored in the $c
variable.
Stop-Computer
shuts down the computers specified with the ComputerName parameter's list of
computers in the $s
variable. The Force parameter forces an immediate shutdown. The
Credential parameter submits the credentials saved in the $c
variable.
Parameters
-ComputerName
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 doesn't rely on PowerShell remoting. You can use the ComputerName parameter even if your computer isn't configured to run remote commands.
Type: | String[] |
Aliases: | CN, __SERVER, Server, IPAddress |
Position: | 0 |
Default value: | None |
Required: | False |
Accept pipeline input: | True |
Accept wildcard characters: | False |
-Confirm
Prompts you for confirmation before running the cmdlet.
Type: | SwitchParameter |
Aliases: | cf |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Credential
Specifies a user account that has permission to do this action. The default is the current user.
Type a user name, such as User01 or Domain01\User01, or enter a PSCredential object
generated by the Get-Credential
cmdlet. If you type a user name, you're prompted to enter the
password.
Credentials are stored in a PSCredential object and the password is stored as a SecureString.
Note
For more information about SecureString data protection, see How secure is SecureString?.
Type: | PSCredential |
Position: | 1 |
Default value: | Current user |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-Force
Forces an immediate shut down of the computer.
Type: | SwitchParameter |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WhatIf
Shows what would happen if the cmdlet runs. The cmdlet isn't run.
Type: | SwitchParameter |
Aliases: | wi |
Position: | Named |
Default value: | False |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
-WsmanAuthentication
Specifies the mechanism that is used to authenticate the user credentials when this cmdlet uses the WSMan protocol. The default value is Default.
The acceptable values for this parameter are:
- Basic
- CredSSP
- Default
- Digest
- Kerberos
- Negotiate.
For more information about the values of this parameter, see AuthenticationMechanism.
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 PowerShell 3.0.
Type: | String |
Accepted values: | Default, Basic, Negotiate, CredSSP, Digest, Kerberos |
Position: | Named |
Default value: | Default |
Required: | False |
Accept pipeline input: | False |
Accept wildcard characters: | False |
Inputs
None
You can't pipe objects to this cmdlet.
Outputs
None
This cmdlet returns no output.
Notes
This cmdlet uses the
Win32Shutdown
method of the Win32_OperatingSystem
WMI
class. This method requires the SeShutdownPrivilege
privilege be enabled for the user account
used to shutdown the machine.
In PowerShell 7.1, Stop-Computer
was added for Linux and macOS. For these platforms, the cmdlet
calls the native command /sbin/shutdown
.