# dot source the function into our session
. ".\Invoke-Parallel.ps1"
# Get full help details
Get-Help Invoke-Parallel -full
# Create PSObject array
$pstablelist = @();
invoke-parallel -InputObject $(get-content .\ServerIps.txt) -throttle 100 -runspaceTimeout 30 -ScriptBlock {
# Clear $value
$value = &null
if($ping = Test-Connection -ComputerName $_ -BufferSize 16 -quiet -count 1){
Try{
# Set service property value
set-service -ComputerName $_ -name "tabletinputservice" -startuptype "manual"
$set = "set succeed"
}
Catch{
$set = "set failed"
}
Try{
# Get service property value to check
$value = get-service -ComputerName $_ -name "tabletinputservice" | select "starttype"
}
Catch{
$value = "get failed"
}
}
# Create a Hash table where the contents of key are the column names that will be exported to CSV,
# and the contents of value are the values that will be exported to CSV
$table = @{ "ComputerName"=$_; "Ping"=$ping; "Service"="tabletinputservice"; "Set State" = $set; "Value" = $value; };
# Convert the Hash table to PSObject
$pstable = New-Object -TypeName PSObject -Prop $table;
# Insert the converted PSObject into the array and wait for the output
$pstablelist += $pstable;
}
$pstablelist | Export-Csv .\Output.csv -NoTypeInformation
SetServices-Parallel.ps1
最新推荐文章于 2024-05-26 16:33:56 发布