How would I make this script more efficient?
I have a lot of scripts that configure a batch of machines using a CSV file as the variable data and run a foreach on each line of the $csv and run a specific command against all the servers in sequence... Problem is, if I have 30 machines hooked up it takes about 3 minutes to power them all off before it's complete.
sample code:
$Path1 = "C:\powershell\CSV\Gen9.csv"
$csv1 = Import-Csv $Path1
#POWEROFF AND SET LEGACY BOOT
Foreach ( $server in $csv1 ) {
write-host Now Powering off Server $server.Serialnum -ForegroundColor Yellow
Set-HPiLOHostPower -WarningAction SilentlyContinue -server $Server.DHCPIP -Username "Administrator" -Password $Server.DefaultPW -Hostpower OFF -DisableCertificateAuthentication
}
and so on and so forth.
I have read about foreach -parallel but never understood workflows enough to really grasp the concept.
it'd be great if somehow i can turn that script block to run parallel against all machines in the csv at once.
Posted Apr 12, 2017, 1:08 AM UTC
611