简体   繁体   中英

Filtering out ".onmicrosoft.com" adresses from ProxyAdresses - Get-AzureADUser

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" } | 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! :)

Thank You Theo for providing your suggestion. Converting it to as an answer to help other community member.

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

在此处输入图片说明

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"}}

在此处输入图片说明

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