简体   繁体   中英

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

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} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM