title: Powershell matching TWO values in an array/object
body: <p>I'll explain what I am trying to achieve first in case there is a better way than what I have wrote. I am trying to get a list of users (but in below example I am only querying one user to test the script) who have an Exchange plan set to disabled.</p>
  
  <p>The filter I need to apply is on the licenses.servicestatus object. If you run and output of this object your get:</p>
  
  <pre><code>ServicePlan           ProvisioningStatus
  -----------           ------------------
  INTUNE_O365           PendingActivation 
  YAMMER_ENTERPRISE     PendingInput      
  RMS_S_ENTERPRISE      Success           
  OFFICESUBSCRIPTION    Success           
  MCOSTANDARD           Disabled          
  SHAREPOINTWAC         Disabled          
  SHAREPOINTENTERPRISE  Disabled          
  EXCHANGE_S_ENTERPRISE Success  
  </code></pre>
  
  <p>What I need is the query to return true if it finds "disabled" in the provisioningstatus column and a matching "exchange" wildcard in the serviceplan column.</p>
  
  <p>My script below does not do this, instead it returns true if it finds disabled and exchange in ANY order, IE it will always return true as long as disabled and Exchange are anywhere in the table, not where they both match on one row. This is as close as I can get as to what I want.</p>
  
  <pre><code>Get-MsolUser -UserPrincipalName "exampleuser@dom.com"| ? {"disabled" -in $_.licenses.servicestatus.provisioningstatus -and ($_.licenses.servicestatus| Out-String| ? {$_ -like "*exchange*"})}
  </code></pre>
  
  <p>I can see where I am going wrong, I just don't know how to fix it. The script is effectively running two separate searches rather than combining them together.</p>
  
  <p>Also Note the reason I am using out-string is because the table above does not output serviceplan as a string.</p>
  
  <p>If there is a better way of doing this then please advise otherwise I just need to know how to match two conditions in an array from the same row.</p>