Powershell Azure ActiveDirectory

I am trying to filter only the email with dot(Sam.Smith@forfun.com). But all email would be displayed to me. Is this somehow possible to get only “Sam.Smith@forfun.com” this? I try it in powershell.

    PS C:\Users\Rayman>  Get-AzureADUser -SearchString "Sam".AlternateEmailAddresses
    PS C:\Users\Rayman>  (Get-AzureADUser -SearchString "Sam Smith").UserPrincipalName
    PS C:\Users\Rayman> Get-AzureADUser -SearchString "Sam Smith"| Select Mail

I have tried many variants without success.

Have you tested to add | Where-Object {$_ -like "*.*"} at the end of your commands?

yes, the problem is both email address have point. but I only want Sam.Smith@forfun.com

I recommend using AD activities from any of these packages:


Hi, I need to figure it out first time at powershell. The Uipath should make it possible for me later. regards

Could you test with the pattern "*.*@*" instead?

| Where-Object {$_ -like "*.*@*"}

Yes unfortunately did not work

OK, that’s strange. It should work if it’s an array. Maybe the emails are just a string with a line break in between. In that case you would need to split it into an array first.

Sorry I do not quite understand. I have to search it before as first name and last name. (Get-AzureADUser -SearchString “name surname”) As a result I get for some users different and multiple email address of . But I need only email address between first name and last name a dot. The others should not be shown to me.

as you see 2 different emailadress from the same user. First email is the right one

You need to get the emails first before using Where-Object, something like this:

Get-AzureADUser -SearchString "Sam Smith" | where {$_.UserPrincipalName} | Where-Object {$_ -like "*.*@*"}

did not work unfortunately But thank you. Found other solution thanks for tip about array:
PS C:\Users\Rayman> (Get-AzureADUser -SearchString “Sam Smith”| Select Mail)[0].

Array [0] is for every user the right mail

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.