title: Powershell return matching row from SQL query results from AD Computer list
body: <p>I'm lost, apologies if similar questions to this have been asked before. All my searching has come up empty.</p>
  
  <p>How can I iterate through SQL query results in <code>$Results</code> matching server names in <code>$servers</code> if it helps, is created using</p>
  
  <pre><code>#Change OS to OperatingSystem, shortened for screen readability.
  $servers = Get-ADComputer -LDAPFilter "(|(OS=*2003*)(OS=*2000*))" | Select -expand Name
  </code></pre>
  
  <p>I got as far as trying this:</p>
  
  <pre><code>$servers | ForEach-Object { $Results.Server -match $_}
  </code></pre>
  
  <p>But the output contains multiple duplicate items at the end.</p>
  
  <p>I also had thought of producing a huge SQL query, so only one query needs to be run, as an example:</p>
  
  <pre><code>$SqlQuery = @'
  SELECT swName AS [Server], swSchedule as [Schedule]
   FROM SW_TABLE
  WHERE (swSchedule = 'Weekly' OR swSchedule = 'SCCM - Weekly' OR swSchedule = 'Monthly')
  AND swRootObjectType = 'Server'
  AND swName = 'Server'
  AND swName = 'Server'
  AND swName = 'Server'
  AND swName = 'Server'
  '@
  </code></pre>