Home > Software design >  Filtering out ".onmicrosoft.com" adresses from ProxyAdresses - Get-AzureADUser
Filtering out ".onmicrosoft.com" adresses from ProxyAdresses - Get-AzureADUser

Time:11-05

I was wondering if there is a way to filter the result under proxyadresses when i run:

$Users = Get-AzureADUser -All:$true | Select-Object DisplayName, mail, @{n="ProxyAddresses";e={$_.ProxyAddresses -join "`r`n"}}

The result of that would be kinda like this atm..

DisplayName        Mail                    ProxyAddresses
-----------        ----                    --------------
name1              name1@email.com         smtp:name1@email.com
name2              name2@email.com         SMTP:name2@email.com, SMTP:admin@email.com, smtp:name2@email.com.onmicrosoft.com...
name3              name3@email.com         smtp:name@email.com.onmicrosoft.com...

and im plotting this into a html table in hudu after. atm this works fine. but i would like it if there was a way to exclude the "onmicrosoft" adress from there. i dont want to use | Where-Object { $_.ProxyAddresses -notmatch "onmicrosoft" } because that would just remove every user that in an alias.

could it be possible to just do a -replace somehow, and then replace it with an empty string?

I would be super happy for any help with this! :)

CodePudding user response:

Thank You enter image description here

Replace with below code for getting the user excluding .onmicrosoft.com

$Users = Get-AzureADUser -All:$true | Select-Object DisplayName, mail, @{n="ProxyAddresses";e={($_.ProxyAddresses | Where-Object {$_ -notmatch 'onmicrosoft'}) -join "rn"}}

enter image description here

  • Related