title: How can I check in powershell if Get-ChildItem has failed?
body: <p>In my powershell script I have the following line:</p>
  
  <pre><code>$DirectoryInfo = Get-ChildItem $PathLog | Where-Object { $_.PSIsContainer }
  </code></pre>
  
  <p>to read some data from the path given in the variable <code>$PathLog</code>. But I realizes that even if the <code>Get-ChildItem</code> command failed (for example, the given path in <code>$PathLog</code> does not exist), and an error is written to the shell, the script continues. </p>
  
  <p>How can I check if this <code>Get-ChildItem</code> was successfull? I want to use it to trigger an <code>if</code> clause as follows which stops the script at that moment:</p>
  
  <pre><code>if (???) {
      "There was an error"
      return
  }
  </code></pre>
  
  <p>What to put into the brackets? How how to do it otherwise?</p>