Get sAMAccountNames from CSV of Proxy Address powershell

Tagged: 

This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Dan Potter Dan Potter 1 month, 2 weeks ago.

  • Author
    Posts
  • #55541
    Profile photo of maxcoder
    maxcoder
    Participant

    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

  • #55685
    Profile photo of Dan Potter
    Dan Potter
    Participant

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

  • #55780
    Profile photo of Dan Potter
    Dan Potter
    Participant

    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

You must be logged in to reply to this topic.