PowerTip: Turn off the power to your computer with PowerShell

The Scripting Guys

Dr Scripto

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 ‘computer0http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg9/04/hsg_perf4_0http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg.jpg9/04/hsg-02-http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg9/04/hsg_perf4_0http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg.jpg7-http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg9/04/hsg_perf4_0http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg.jpg0-03.jpg9/04/questsoftware.png9/04/a-sm.jpg9/04/q-sm.jpg’,’computer02′,’computer03′ -whatif

# Stop multiple systems

Stop-computer -ComputerName ‘computer0http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg9/04/hsg_perf4_0http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg.jpg9/04/hsg-02-http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg9/04/hsg_perf4_0http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg.jpg7-http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg9/04/hsg_perf4_0http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/20http://devblogs.microsoft.com/scripting/wp-content/uploads/sites/29/2019/04/2010_scriptgames_badge1.png9/04/hsg_perf3_02.jpg.jpg0-03.jpg9/04/questsoftware.png9/04/a-sm.jpg9/04/q-sm.jpg’,’computer02′,’computer03′

Drawing of Dr. Scripto

The Scripting Guys
Dr Scripto

Follow Dr Scripto   

No Comments.