title: Powershell null pointer exception
body: <p>I've been working on and off on a project to compress and move files older than <em>x</em> days to an archival folder.  I've retrofitted the script here: <a href="https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Compress-Log-121e63b5" rel="nofollow">https://gallery.technet.microsoft.com/scriptcenter/PowerShell-Compress-Log-121e63b5</a> to assist me however I'm running into an issue that has proved fairly annoying.</p>
  
  <p>When I run this on my machine, utilizing local directories, the script completes as expected.  However, when I pass networked file paths to the script, the <code>Get-WmiObject</code> query begins returning null results.</p>
  
  <p>For example, this is a sample command line that works:</p>
  
  <pre><code>powershell -executionpolicy remotesigned -File compress_and_move_files.ps1 c:\temp\ c:\temp\compress_test\ 14
  </code></pre>
  
  <p>When I move to a UNC path, I begin getting the null-valued expression error on the WMIQuery.Compress() call</p>
  
  <pre><code>powershell -executionpolicy remotesigned -File compress_and_move_files.ps1 \\server1\temp\ \\server1\temp\compress_test\ 14
  </code></pre>
  
  <p>This is the full error:</p>
  
  <pre><code>You cannot call a method on a null-valued expression.
  At compress_and_move_files.ps1:14 char:23
  + If ($WMIQuery.Compress &lt;&lt;&lt;&lt; ()) {Write-Host "$FullName compressed successfull
  y."-ForegroundColor Green}
      + CategoryInfo          : InvalidOperation: (Compress:String) [], RuntimeE
     xception
      + FullyQualifiedErrorId : InvokeMethodOnNull
  </code></pre>