0

I've got a script which goes out to computer names from a text file and then polls the services on those machines and writes the results back to a text file.

Here's what I currently have set up:

$Computers = Get-Content computername.txt 

$Output = Foreach ($Computer in $Computers) {
    Write-Output  "`n" "Status of $Computer".ToUpper()
    Get-WMIobject -Computername $Computer win32_service | Where-Object {$_.startname -ne "LocalSystem" -and $_.startname -ne "localservice" -and $_.startname -notlike "*AUTHORITY*"} | ft name, startname, startmode, state 
}

$Output | Out-File ServiceReport.txt

Is there a way to run multiple sessions at once instead of processing this incrementally? IE - send the command to all the systems at once and then receive the response and record appropriately? I've looked in to Invoke-Command and a few other things but have yet to improve time, get results to write back to the file, or get those options working generally.

1 Answer 1

2

Get-WMIObject will multi-thread. You just need to give it more than one computer at a time to work with:

$Computers = Get-Content computername.txt 

Get-WMIobject -Computername $Computers win32_service |
 Where-Object {$_.startname -ne "LocalSystem" -and $_.startname -ne "localservice" -and $_.startname -notlike "*AUTHORITY*"} |
 ft PSComputerName, name, startname, startmode, state |
 Out-string |
 Out-File ServiceReport.txt

You'll lost the ability to have that "Status of $Computer" line before each one but you can make up for it by including the computer name in the selected objects.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.