I'm trying to make the following script multithreaded but I dont think the search for A/D computers is working correctly. After all of the jobs start, they all error out right away. The code inside "ScriptBlock" should work, by itself, but I cant seem to get it to work with the extra multithreading code.
Objective: Create a script that searches A/D for computer descriptions that start with a hyphen. If found, it will shutdown a PC.
Here is what I have so far...
Get-ADComputer -Filter * |`
$time = Get-Date
$dsc = (Get-WmiObject -Class Win32_OperatingSystem -computerName $_.Name -errorAction silentlyContinue);
write-host $time.Hour$time.Minute The RPC server is unavailable on this computer!
write-host $time.Hour$time.Minute This computer has no description!
$chkName = $dsc.description.StartsWith("-");
write-host $time.Hour$time.Minute Initiating FAKE Shutdown of Remote Host $_.Name -ForegroundColor DarkYellow
# Execute the jobs in parallel
# Wait for it all to complete
While (Get-Job -State "Running")
# Getting the information back from the jobs
Get-Job | Receive-Job