Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get-ADUser where custom attribute IS null

I need to query AD for user who have custom extensionAttribute10 not set OR not equal to specific value. I successfuly get the users with value not equal to 100 with that command:

Get-ADUser -SearchBase "ou=OU1,ou=Users,dc=domain,dc=local" -filter 'extensionAttribute10 -ne "100"'

What should I add to get also those with the value ? I've tried diffrent ways but nothing worked.

Please help

like image 781
IGOR LEVKOVSKY Avatar asked Oct 16 '25 21:10

IGOR LEVKOVSKY


2 Answers

To get users where an attribute is not set, you'd use -notlike "*". Use -or to combine that with the filter you already have:

Get-ADUser -SearchBase "ou=OU1,ou=Users,dc=domain,dc=local" -filter 'extensionAttribute10 -ne "100" -or extensionAttribute10 -notlike "*"'
like image 98
Gabriel Luci Avatar answered Oct 18 '25 12:10

Gabriel Luci


use this

get-aduser -filter * -SearchBase "ou=OU1,ou=Users,dc=domain,dc=local"
-Properties * | ? {$_.extensionAttribute10 -eq $null -or $_.extensionAttribute10 -eq 100}
like image 33
teddy tresor mabulay Avatar answered Oct 18 '25 14:10

teddy tresor mabulay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!