Exclude groups from (Get-ADGroup)

I’m trying to exclude a list of groups from the get-adgroup command, what am I doing wrong?

 

 $exclude = @("Print Operators", "Replicator", "Remote Desktop Users")
Get-ADGroup -Filter * -Properties name | where {$_.name -notcontains $exclude} | select name

You have it backwards.

PS /Users/js> 'name1' -notcontains 'name1','name2','name3'
True

PS /Users/js> 'name1','name2','name3' -notcontains 'name1'
False

Change the -notcontains to -notin.

$exclude = @("Print Operators", "Replicator", "Remote Desktop Users")
Get-ADGroup -Filter * -Properties name | where {$_.name -notin $exclude} | select name

pwshliquori

Yes, you can use -notin. Bizarrely, you can actually use -eq with arrays.

PS /Users/js> $list = 1,2,3

PS /Users/js> 1 | where { -not ($list -eq $_) } 

PS /Users/js> 4 | where { -not ($list -eq $_) } 
4