PowerShell Script to Shutdown Remote Computers using PSShutdown

I needed some software/script to shutdown group of chosen computers at a time specified in windows scheduler. I Googled …. and after some research I put this script together:

$erroractionpreference = “SilentlyContinue”

$psSwitches = ” -s -f -c -t 30″
$psMessage = ” -m” + ‘ “Please press CANCEL button if you want to CONTINUE to work. DO NOT forget to shutdown your computer before you leave”‘

$strComputer = get-content “computers.txt”
$application = “psshutdown.exe”

Foreach ($i in $strComputer)
$arguments = “\\$i” + $psSwitches + $psMessage
# write-host $arguments

As you can see, I used one of the PSTools applications to do it :)
Powershell has it’s own ways to perform the task using Win32Shutdown Method of the Win32_OperatingSystem Class, and I will try it next time… ;)

Tags: , ,

Locations of visitors to this page