title: Powershell - WMI error via remote connection
body: <p>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:</p>
  
  <pre><code>$DHCP = Get-WmiObject win32_service -ComputerName $server 2&gt;&gt;$logerror2 | 
  Where-Object -FilterScript {$_.Name -eq "dhcp"} 
  </code></pre>
  
  <p>I created object with two properties:</p>
  
  <pre><code>              [pscustomobject][ordered]@{
                ServerName = $server
                DHCP = $DHCP.State
                }
  </code></pre>
  
  <p>The output is directed to the .csv file, content of the file looks like this:</p>
  
  <pre><code>"ServerName","DHCP"
  "srv1","Running"
  "srv2",,
  "srv3",,
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>"ServerName","DHCP"
  "srv1","Running"
  "srv2",WMI Problem,
  "srv3",WMI Problem,    
  </code></pre>