IGOR LEVKOVSKY
IGOR LEVKOVSKY

Reputation: 167

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

Upvotes: 4

Views: 22465

Answers (3)

vladimir
vladimir

Reputation: 1

use where-object or ? take long time

for me help

get-aduser -filter {-not(extensionAttribute15 -like "*")}

Upvotes: 0

teddy tresor mabulay
teddy tresor mabulay

Reputation: 157

use this

get-aduser -filter * -SearchBase "ou=OU1,ou=Users,dc=domain,dc=local"
-Properties * | ? {$_.extensionAttribute10 -eq $null -or $_.extensionAttribute10 -eq 100}

Upvotes: 1

Gabriel Luci
Gabriel Luci

Reputation: 40928

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 "*"'

Upvotes: 5

Related Questions