I wrote script in powershell, scrips collects info about status of some system services, for example DHCP service on remote hosts. Sometimes there is a problem with connection to the remote hosts and collect info from WMI. The WMI command below:
$DHCP = Get-WmiObject win32_service -ComputerName $server 2>>$logerror2 |
Where-Object -FilterScript {$_.Name -eq "dhcp"}
I created object with two properties:
[pscustomobject][ordered]@{
ServerName = $server
DHCP = $DHCP.State
}
The output is directed to the .csv file, content of the file looks like this:
"ServerName","DHCP"
"srv1","Running"
"srv2",,
"srv3",,
On hosts named "srv2" and "srv3" there is a problem with connection and gathering info from remote hosts WMI. I would like instead of blank space to give some info, for example "WMI Problem", and the content of the file should looks like this:
"ServerName","DHCP"
"srv1","Running"
"srv2",WMI Problem,
"srv3",WMI Problem,