Powershell: Find all computers in AD but exclude certain OU's
<p>I am trying to list all computers in my domain except for those stored in any of the two OU's. As soon as I add the second OU using the -or operator things break.</p>

<p>Using this I return all computers except for those stored in my first unwanted ou:</p>

<pre><code>[array]$Computers1 = get-adcomputer -filter '*' -SearchBase 'ou=WorkStations,dc=XXX,dc=XXX,dc=edu' | where { $_.DistinguishedName -notlike "*OU=Test,*" }
</code></pre>

<p>Adding the -Or operator causes the unwanted computers (those stored in both of these OU's) to be included in my results.</p>

<pre><code>[array]$Computers1 = get-adcomputer -filter '*' -SearchBase 'ou=WorkStations,dc=XXX,dc=XXX,dc=edu' | where { ($_.DistinguishedName -notlike "*OU=Test,*") -or ($_.DistinguishedName -notlike "*OU=TIS,*")}
</code></pre>