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
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 "*"'
use this
get-aduser -filter * -SearchBase "ou=OU1,ou=Users,dc=domain,dc=local"
-Properties * | ? {$_.extensionAttribute10 -eq $null -or $_.extensionAttribute10 -eq 100}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With