简体   繁体   中英

Get sAMAccountNames from CSV of Proxy Address powershell

I have got the value in the file is under the SMTPproxyaddresses header.So, I'm trying something along this lines.

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

I couldn't get it working with a variable inside the Filter parameter, but it worked typed outright. However, the alternative is using an LDAPFilter and this worked for me.

    Get-AdUser -LDAPfilter "(ProxyAddresses=*$($user.SMTPaddresses))" -Properties whenCreated, Enabled, SamAccountName

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM