简体   繁体   中英

Pulling User Object's Primary SMTP from ProxyAddresses

I have a PS script that is pulling Employee IDs from a CSV file that I update every morning that I get from HR just to make sure the automation is running correctly by adding/changing their email, extensionAttribute 1, and the ProxyAddresses. I would like it to only check for the Primary SMTP instead of all ProxyAddresses but am having trouble.

Import-Csv "C:\temp\HRfeed101519.csv" | foreach {Get-ADUser $_.EmpID -Properties * | fL mail, extensionattribute1, Proxyaddresses}

The ProxyAddresses field identifies the PrimarySMTPAddress with the SMTP: tag. Therefore, you can query for that specifically and output it as a calculated property.

Get-ADUser $_.EmpID -prop ProxyAddresses,Mail,ExtensionAttribute1 |
    Select-Object Mail,ExtensionAttribute1,ProxyAddresses,
    @{Name='PrimarySMTPAddress';Expression={$_.ProxyAddresses -cmatch '^SMTP:' -creplace 'SMTP:'}}

-cmatch and -creplace perform case-sensitive regex matching.


Note: The default table display of the output may not show all of the properties and values due to collection size stored in ProxyAddresses . You can pipe your output to Format-List to see all properties, but do not store the Format-List output in a variable.

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