Author Posts

October 21, 2016 at 11:15 am

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

October 21, 2016 at 1:44 pm

get-aduser -filter "anr -eq 'smtp:userproxy@contoso.com'"

October 21, 2016 at 2:19 pm

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

October 22, 2016 at 1:05 pm

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