Get sAMAccountNames from CSV of Proxy Address powershell

Welcome Forums General PowerShell Q&A Get sAMAccountNames from CSV of Proxy Address powershell

This topic contains 3 replies, has 2 voices, and was last updated by

 
Participant
2 years ago.

  • Author
    Posts
  • #55541

    Participant
    Points: 0
    Rank: Member

    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

    Participant
    Points: 21
    Rank: Member

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

  • #55780

    Participant
    Points: 21
    Rank: Member

    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

The topic ‘Get sAMAccountNames from CSV of Proxy Address powershell’ is closed to new replies.