Exclude list of users from get-aduser cmdlet
hello,
i need put exclusion input data
lets say, don't want list "test01, test02, test03" users.
i can write like
get-aduser -filter * |?{$_.name -ne "test01" -and $_.name -ne "test02" ..}
im sure there more candy-like way accomplish this.
something like
$exclude = @('test01','test02')
get-aduser -filter * |?{$_.name -notmach $exclude}
propably find answer myself soon, im in hurry , need it to resolve fast..
looks can use -notcontains, tried following test
$users = @("user1","test01","test02","anotheruser") $excludeusers = @("test01","test02") $users | {$excludeusers -notcontains $_}
the results after user1 , anotheruser, possibly work you
$excludedusers = @('test01', 'test02') get-aduser -filter * | { $excludedusers -notcontains $_.samaccountname }
if find post has answered question, please mark answer. if find post helpful in anyway, please click vote helpful.
don't retire technet
Windows Server > Windows PowerShell
Comments
Post a Comment