Link to home
Start Free TrialLog in
Avatar of progjm
progjm

asked on

powershell sleep time

i am new to powershell and hoping I can get some assistance. i am running this script to power down machines during a UPS power failure. How can I put in a sleeptime between each machine in the server.txt file. I have a particular order all machines need to power off

$psSwitches = ” -s -f -c -t 30?"

$strComputer = get-content “Servers.txt”
$application = “psshutdown.exe”
Foreach ($i in $strComputer)
 {
    $arguments = “\\$i” + $psSwitches + $psMessage
    [System.Diagnostics.Process]::start($application,$arguments)
    # write-host $arguments
    }
ASKER CERTIFIED SOLUTION
Avatar of Rajitha Chimmani
Rajitha Chimmani
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of progjm
progjm

ASKER

thanks

I will give it a shot here in a bit
BTW, you do not need to use [System.Diagnostics.Process]::start for those calls. psshutdown (and almost all other external commands) can be run directly:
gc “Servers.txt” | % {
  psshutdown \\$_ -s -f -c -t 30
  start-sleep -s 10
}

Open in new window

Avatar of progjm

ASKER

Sorry Qlemo saw your add after i accepted a solution, but thank you!