Select email address from UPN variable?

How can I select only the email address from the UPN variable, so $useremail -eq $ADUPN is true?

userPrincipalName

james.bond@contoso.local

PS C:\Windows\system32> $useremail
james.bond@contoso.local

PS C:\Windows\system32> $useremail -eq $ADUPN
False

Assuming:

userPrincipalName
—————–
james.bond@contoso.local

is what is shown when you use

PS C:\Windows\system32> $ADUPN

Then

PS C:\Windows\system32> $useremail -eq $ADUPN.userPrincipalName

By the way, UPN is not an email address, it’s a userPrincipalName, which may or may not be the same as the user;s email address depending on how the environment is setup.

Thanks a lot! :slight_smile:

That did the trick. Know its not the same, migrating from Lotus notes to Office 365 and whant to check that emailadress and UPN is the same, if not flag it to Helpdesk in a email.

First I thought it was my logical statement that was wrong, until I checked what $ADUPN outputted.