Get sAMAccountNames from CSV of Proxy Address powershell

This topic contains 3 replies, has 2 voices, and was last updated by  Dan Potter 1 year, 7 months ago.

  • Author
  • #55541


    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' Error Message: 'syntax error'

        foreach ($user in $userID)
        	$ADuser = Get-ADUser -Filter "ProxyAddress -eq $($user.SMTPproxyaddresses)" -Properties whenCreated, Enabled, SAMAccountName

    CSV file :


  • #55685

    Dan Potter

    get-aduser -filter "anr -eq ''"

  • #55780

    Dan Potter

    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


You must be logged in to reply to this topic.