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\:.*'}
}