I am using this to check if a server has dhcp enabled after setting it to static with another script. My issue is i can't seem to figure out how to export the errors. for example if i put a fake server name in my $servers file i can see it effor abut all my attempts to output it to the errorlog it only shows the text. if i try to say add-content -path $errorlog "WMI error $server". it shows everything but the $server variable. I have removed my error checking since it didn't work and put the working portion in the post. This is my first attempt at using jobs.
$Cred = Get-Credential
$output = "c:\temp\DhcpCheck.csv"
$servers = Get-Content "c:\temp\serverlist.txt"
$completed = $false
foreach($server in $servers){
get-wmiobject -class Win32_Networkadapterconfiguration -Credential $cred -asjob -ComputerName $server
}
while($completed -eq $false){
if((get-job | where{$_.state -eq "Running"}).count -eq 0){
$completed = $true
}
else{
Start-Sleep -Seconds 5
}
}
$results = get-job | receive-job | where {$_.defaultipgateway -like "*.*"} | select PSComputerName,DHCPEnabled,description,caption | Export-Csv $output -NoTypeInformation
Get-Job | Remove-Job