Bill Addison
Bill Addison

Reputation: 53

PowerShell Get-ADUser with ANR

I'm trying to search Active Directory for a user with the following statement, but I get an error when I use $("smtp:$user").

get-aduser -filter {(anr -eq $user) -or (anr -eq $("smtp:$user"))}

Could anyone explain why please, or is there a better way of achieving the same result. I would like user to be able to contain, Name, email or SAM information, and use the same code to search.

get-aduser : Cannot process argument because the value of argument "path" is not valid. Change the value of the "path" argument and run the operation again.
At line:1 char:1.
get-aduser -filter {(anr -eq $user) -or (anr -eq $("smtp:$user"))}
CategoryInfo:NotSpecified: (:) [Get-ADUser], PSArgumentException
FullyQualifiedErrorId:ActiveDirectoryCmdlet:System.Management.Automation.PSArgumentException,Microsoft.ActiveDirectory.Management.Commands.GetADUser

Upvotes: 0

Views: 1710

Answers (1)

Judd Davey
Judd Davey

Reputation: 349

I'm not sure exactly what you are trying to achieve, as the first condition will include anything in the second condition.

Does this look better?:

$user = "SmithJ"
$SMTP = "smtp:$user"

Get-ADUser -Filter {anr -eq $user -or anr -eq $SMTP} 

Upvotes: 0

Related Questions