July 16th, 2018

PowerTip: Turn off the power to your computer with PowerShell

Doctor Scripto
Scripter

Summary: A simple way to power off your computer by using the Windows PowerShell cmdlets.

   Hey, Scripting Guy! I’ve got a script that needs to power off a system after it’s done. How can I accomplish this with PowerShell?

   Look no further than the Stop-Computer cmdlet to turn off the power! (How’s THAT for a power tip?) Here are some examples:

# Try without doing anything bad

Stop-Computer -WhatIf

# Stop the local computer

Stop-Computer

# Try without doing anything bad on multiple systems

Stop-computer -ComputerName ‘computer01′,’computer02′,’computer03’ -whatif

# Stop multiple systems

Stop-computer -ComputerName ‘computer01′,’computer02′,’computer03’

Drawing of Dr. Scripto

Author

The "Scripting Guys" is a historical title passed from scripter to scripter. The current revision has morphed into our good friend Doctor Scripto who has been with us since the very beginning.

1 comment

Discussion is closed. Login to edit/delete existing comments.

  • Bob Jo

    hey Scripting Guy –  What a great tip !!  Thanks.   Now, how about a script to start the remote computer after I have used this script to shut it down ??   You know, kinda like the old  WOL  used to do.  That would really be nice !!!  and convenient !!!   Would save lots of driving time.   Looking forward to seeing your solution …