title: PowerShell Not Member of Group
body: <p>I'm looking at <a href="https://stackoverflow.com/questions/26180988/powershell-get-adcomputer-properties-memberof">Powershell - Get-ADComputer -properties memberof</a> and it's not working for me. The match always returns true. So I'll use something simple like Domain Computers in the group list and the <code>-notmatch</code> should filter out anything that is part of the Domain Computers group, well it still returns computers that are part of Domain Computers. All I want is a script that takes the computers and checks their membership against a list of groups and returns them if they are <strong>not</strong> part of that group list. </p>
  
  <pre><code>$groups = @("Terminal Server License Servers","Exchange Trusted Subsystem","Cert Publishers","Domain Computers")
  $regex = '^({0})' -f ($groups -join '|')
  get-adcomputer -Filter {OperatingSystem -like "Windows Server 200*"} -properties * | Where-Object{($_.MemberOf | Get-ADGroup).Name -notmatch $regex} | Select-Object Name | fl
  </code></pre>