title: Powershell IF Statements
body: <p>I'm having a go at trying to create a quick IF Statement for disabling/ enabling a webcam.</p>
  <p>So far, I've come up with this:</p>
  <pre><code>$InstIDDisabled = Get-PnpDevice -FriendlyName &quot;Camname&quot; -Status error
  $InstIDEnabled = Get-PnpDevice -FriendlyName &quot;Camname&quot; -Status OK
  If($InstIDDisabled.Status -eq &quot;error&quot;){
  Enable-PnpDevice -InstanceId $InstIDDisabled.InstanceId -Confirm:$false
  else
  Disable-PnpDevice -InstanceId $InstIDEnabled.InstanceId -Confirm:$false}
  </code></pre>
  <p>The result I get is:</p>
  <pre><code>Get-PnpDevice : No matching Win32_PnPEntity objects found by CIM query for instances of the ROOT\cimv2\Win32_PnPEntity class on the  CIM server: 
  SELECT * FROM Win32_PnPEntity  WHERE ((Name LIKE 'Camname')) AND ((Status = 'error')). Verify query parameters and retry.
  At line:1 char:19
  + ... DDisabled = Get-PnpDevice -FriendlyName &quot;Camname&quot; -Status erro ...
  +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (Win32_PnPEntity:String) [Get-PnpDevice], CimJobException
      + FullyQualifiedErrorId : CmdletizationQuery_NotFound,Get-PnpDevice
  </code></pre>
  <p>The error looks like it can't see the webcam by CIM query, but when run individually (removing the IF element) it works.</p>
  <p>Where am I going wrong?</p>