I have got the value in the file is under the SMTPproxyaddresses header.So, I’m trying something along this lines. I am getting Get-ADUser : Error parsing query: ‘ProxyAddress -eq user@contoso.com’ Error Message: ‘syntax error’
foreach ($user in $userID)
{
$ADuser = Get-ADUser -Filter "ProxyAddress -eq $($user.SMTPproxyaddresses)" -Properties whenCreated, Enabled, SAMAccountName
}
CSV file :
SMTPproxyaddresses
userproxy@contoso.com
testproxy@contoso.com
user2proxy@contoso.com
user3proxy@contoso.com
get-aduser -filter “anr -eq ‘smtp:userproxy@contoso.com’”
I dont really understand what you mean. Anyway , I am using Import-Csv to import the CSV file and then loop though all “SMTPproxyaddresses”. I am getting Get-ADUser : Error parsing query: ‘ProxyAddress -eq user@contoso.com’ Error Message: ‘syntax error’.
Input CSV file :
SMTPproxyaddresses
userproxy@contoso.com
testproxy@contoso.com
user2proxy@contoso.com
user3proxy@contoso.com
First the attribute you are looking for is proxyaddresses. Second it’s going to be a multi-valued property so you wont be able to use -eq operator.
I encourage the use of anr, it’s easier and faster to use. In script I tend to use scriptblocks as the filters instead of messing around with the qoutes.
$ADusers = foreach ($user in $userID)
{
$smtp = ‘smtp:’ + $user.SMTPproxyaddresses
Get-ADUser -Filter {anr -eq $smtp} -Properties whenCreated, Enabled, SAMAccountName
}
$adusers