- Reference
- Module:
- Microsoft.PowerShell.Management
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 alternatecredentials, and to force an immediate shut down.
In PowerShell 7.1, Stop-Computer
was added for Linux and macOS. The parameters have no effect onthese 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 localcomputer. 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 moreinformation, seeabout_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 jobresults. The objects are stored in the $results
variable. The $results
variable displays the jobinformation 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. TheWsmanAuthentication 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\Admin01Stop-Computer -ComputerName $s -Force -Credential $c
Get-Content
uses the Path parameter to get a file in the current directory with the list ofdomain computers. The objects are stored in the $s
variable.
Get-Credential
uses the Credential parameter to specify the credentials of a domainadministrator. The credentials are stored in the $c
variable.
Stop-Computer
shuts down the computers specified with the ComputerName parameter's list ofcomputers in the $s
variable. The Force parameter forces an immediate shutdown. TheCredential 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 acomma-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 evenif 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 objectgenerated by the Get-Credential
cmdlet. If you type a user name, you're prompted to enter thepassword.
Credentials are stored in a PSCredentialobject and the password is stored as a SecureString.
Note
For more information about SecureString data protection, seeHow 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 theWSMan 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, seeAuthenticationMechanism.
Caution
Credential Security Service Provider (CredSSP) authentication, in which the user credentials arepassed to a remote computer to be authenticated, is designed for commands that requireauthentication on more than one resource, such as accessing a remote network share. This mechanismincreases the security risk of the remote operation. If the remote computer is compromised, thecredentials 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 theWin32Shutdownmethod of the Win32_OperatingSystem WMIclass. This method requires the SeShutdownPrivilege
privilege be enabled for the user accountused to shutdown the machine.
In PowerShell 7.1, Stop-Computer
was added for Linux and macOS. For these platforms, the cmdletcalls the native command /sbin/shutdown
.
- Rename-Computer
- Restart-Computer
- Test-Connection