I have a script in powershell to hit each server in a list and check if it is online or not. As it was time consuming, I wrote a thread logic to call that script, My script works fine. But I want to split my good/bad servers into two different text files, I cannot hard code it in my script as obviously resource might be used by another thread. If I write it in thread logic my output (both good and bad) will be in the same file. How can I nicely format only desired output?
### Start-MultiThread.ps1 ###
$Servers =Get-Content -Path "C:\Scripts\Servers.txt"
#Start all jobs
ForEach($Server in $Servers){
Start-Job -FilePath "C:\Scripts\ChkOnline.PS1" -ArgumentList $Server
}
#Wait for all jobs
Get-Job | Wait-Job
#Get all job results
Get-Job | Receive-Job |Out-File -FilePath "C:\Scripts\Output.txt"
##ChkOnline.PS1###
Param($Server = "ServerNameHolder")
$PingStatus= Test-Connection $Server -Quiet
If ($PingStatus -eq 1)
{
Return $Server " is online!!"
}
Else
{
Return $Server " is offline!"
}