Stop-Computer (Microsoft.PowerShell.Management) - PowerShell (2024)

  • 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 $jvariable.

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
Stop-Computer (Microsoft.PowerShell.Management) - PowerShell (2024)

FAQs

How to shut down a computer from PowerShell? ›

PowerShell has its commands, also known as cmdlets, to shut down or restart a Windows 10 device. "Stop-Computer" shuts down the Windows 10 system. The command "Restart-Computer" executes a restart.

How do I stop a PowerShell operation? ›

If you open a PowerShell console session and type exit, the console session will terminate.

How do I stop Microsoft PowerShell? ›

Step 1: Open Task Management by pressing Ctrl + Shift + Esc. Step 2: Choose PowerShell from the list, then click the toggle next to "Disabled" on the Startup tab.

How do I force stop a computer? ›

Try the CTRL + ALT + DEL keyboard shortcut. If it works, it will bring up a Settings menu where you can select the Power button in the lower right and choose Shut down.

How do I force quit Windows PowerShell? ›

Right-click the 'Windows' icon and open 'Windows PowerShell (Admin).' Type 'tasklist' and hit 'enter.' Find the app you want to force quit in the list that displays. Type 'taskkill /im insertprogram.exe' (for example, to force quit Microsoft Edge the command is 'taskkill /im msedge.exe'), then hit 'enter.'

How do I exit from PowerShell? ›

Just using the command Exit in PowerShell will prompt the script to terminate.

How to stop a PowerShell script running in the background? ›

The Stop-Job cmdlet stops PowerShell background jobs that are in progress. You can use this cmdlet to stop all jobs or stop selected jobs based on their name, ID, instance ID, or state, or by passing a job object to Stop-Job .

Can PowerShell be turned off? ›

You may disable PowerShell using either the Local Group Policy Editor (available to those on the Pro version of Windows) or the Registry Editor (accessible to all versions of Windows).

How do I stop PowerShell scripts from running? ›

CTRL+C or CTRL+BREAK will do the trick.

Why is PowerShell running on my computer? ›

PowerShell is not a virus and it is a legitimate Windows utility like Command Prompt. But if a virus or malware attacks your computer, your PowerShell may act in an unexpected way – the tool keeps opening on startup in Windows 10/11. Thus, you can run a malware removal tool to scan your computer and remove the threat.

How to shut down a computer using Command Prompt? ›

Key Takeaways. To shut down your Windows 10 PC using Command Prompt, open a Command Prompt Window, then type "shutdown /s" into the window and hit enter. Your PC will shut down in less than one minute. To restart your PC, run "shutdown /r" instead.

How do I shutdown my computer in 30 minutes PowerShell? ›

Type SHUTDOWN /S /F /T number-in-seconds .

Replace number-in-seconds with how long from now (in seconds) you want the computer to shut down. For example, if you want the computer to turn off in 30 minutes, you'd type SHUTDOWN /S /T 1800 .

Top Articles
Latest Posts
Article information

Author: Stevie Stamm

Last Updated:

Views: 6342

Rating: 5 / 5 (60 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Stevie Stamm

Birthday: 1996-06-22

Address: Apt. 419 4200 Sipes Estate, East Delmerview, WY 05617

Phone: +342332224300

Job: Future Advertising Analyst

Hobby: Leather crafting, Puzzles, Leather crafting, scrapbook, Urban exploration, Cabaret, Skateboarding

Introduction: My name is Stevie Stamm, I am a colorful, sparkling, splendid, vast, open, hilarious, tender person who loves writing and wants to share my knowledge and understanding with you.