[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

powershell sleep time

Posted on 2012-08-23
4
Medium Priority
?
1,138 Views
Last Modified: 2012-08-23
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
    }
0
Comment
Question by:progjm
  • 2
4 Comments
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 2000 total points
ID: 38324727
You can try adding the below command within the Foreach loop.

Start-Sleep -s 10

This will pause Windows Powershell for 10 seconds.
0
 
LVL 1

Author Comment

by:progjm
ID: 38324968
thanks

I will give it a shot here in a bit
0
 
LVL 71

Expert Comment

by:Qlemo
ID: 38325622
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

0
 
LVL 1

Author Comment

by:progjm
ID: 38325747
Sorry Qlemo saw your add after i accepted a solution, but thank you!
0

Featured Post

Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
The viewer will learn how to count occurrences of each item in an array.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question