简体   繁体   中英

Query Azure Active Directory For UPN and Primary SMTP Address then export to CSV

I am trying to get a csv containing two columns, UPN and Primary SMTP Address. The primary SMTP address is among other addresses in the ProxyAddresses property and is discernible because the SMTP is all caps, and the secondaries are all lowercase.

So far this is what I have, which returns all of the SMTP addresses in ProxyAddresses column and not just the Primary address with the SMTP: prefix

 $licusers = gc .\licuser_trim.txt
 FOREACH ($user in $licusers)
 {
 Get-MSOLUser -UserPrincipalName $user | Select userprincipalname, Proxyaddresses | ? {$_.ProxyAddresses -cmatch '^SMTP\:.*'} 
 }

Remove Proxyaddresses , it covers the result from {$_.ProxyAddresses -cmatch '^SMTP\\:.*'} , or change "|" to ",".

Try this:

 Get-MSOLUser -UserPrincipalName $user | Select userprincipalname, @{e={$_.ProxyAddresses -cmatch '^SMTP\:.*'};name='Primaryaddress'},Proxyaddresses

or

Get-MSOLUser -UserPrincipalName $user| Select Proxyaddresses | select {$_.ProxyAddresses -cmatch '^SMTP\:.*'} 

It will return the primary email address indicated by uppercase "SMTP:".

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