# Get sAMAccountNames from CSV of Proxy Address powershell

**URL:** <https://forums.powershell.org/t/get-samaccountnames-from-csv-of-proxy-address-powershell/7384>\
**Category:** PowerShell Help\
**Created:** [October 21, 2016, 5:45am UTC](https://forums.powershell.org/t/get-samaccountnames-from-csv-of-proxy-address-powershell/7384 "2016-10-21T05:45:40Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![maxcoder](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@maxcoder](https://forums.powershell.org/u/maxcoder)\
**Post date:** [October 21, 2016, 5:45am UTC](https://forums.powershell.org/t/get-samaccountnames-from-csv-of-proxy-address-powershell/7384/1 "2016-10-21T05:45:40Z")

</div>

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](mailto: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

```

---

<div class="post-metadata">

**Author:** ![dan-potter](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dan-potter/32/138_2.png) [@dan-potter](https://forums.powershell.org/u/dan-potter)\
**Post date:** [October 21, 2016, 8:14am UTC](https://forums.powershell.org/t/get-samaccountnames-from-csv-of-proxy-address-powershell/7384/2 "2016-10-21T08:14:22Z")

</div>

get-aduser -filter “anr -eq ‘smtp:userproxy@contoso.com’”

---

<div class="post-metadata">

**Author:** ![maxcoder](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@maxcoder](https://forums.powershell.org/u/maxcoder)\
**Post date:** [October 21, 2016, 8:49am UTC](https://forums.powershell.org/t/get-samaccountnames-from-csv-of-proxy-address-powershell/7384/3 "2016-10-21T08:49:35Z")

</div>

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](mailto:user@contoso.com)’ Error Message: ‘syntax error’.

Input CSV file :

SMTPproxyaddresses  
[userproxy@contoso.com](mailto:userproxy@contoso.com)  
[testproxy@contoso.com](mailto:testproxy@contoso.com)  
[user2proxy@contoso.com](mailto:user2proxy@contoso.com)  
[user3proxy@contoso.com](mailto:user3proxy@contoso.com)

---

<div class="post-metadata">

**Author:** ![dan-potter](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/dan-potter/32/138_2.png) [@dan-potter](https://forums.powershell.org/u/dan-potter)\
**Post date:** [October 22, 2016, 7:35am UTC](https://forums.powershell.org/t/get-samaccountnames-from-csv-of-proxy-address-powershell/7384/4 "2016-10-22T07:35:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:40pm UTC](https://forums.powershell.org/t/get-samaccountnames-from-csv-of-proxy-address-powershell/7384/5 "2024-05-16T20:40:12Z")

</div>


