使用Get-AzureADUser在PowerShell中从"SMTP:email@domain.com"中删除"SMTP" [英] Remove 'SMTP' from 'SMTP:email@domain.com' in PowerShell using Get-AzureADUser
问题描述
我正在使用以下脚本为O365中的用户显示别名,这些别名最终将要导出.
I am using the below script to display aliases for users in O365 which I will eventually be exporting.
Get-AzureADUser |
Select-Object @(
@{L = "Name"; E = { $_.DisplayName}}
@{L = "Email"; E = { $_.UserPrincipalName}}
@{L = "Aliases"; E = { $_.ProxyAddresses -join ";"}}
)
在别名(ProxyAddresses
)列中,按预期显示所有由;
分隔的别名,但在所有别名之前还包括SMTP:
.
In the Aliases (ProxyAddresses
) column, it displays all the aliases separated by a ;
as expected but it also includes SMTP:
in front of all of them.
是否可以从这些值中删除SMTP:
?
Is there a way to remove the SMTP:
from these values?
当前结果:SMTP:email@domain.com;SMTP:email2@domain.com
所需结果:email@domain.com;email2@domain.com
推荐答案
Get-AzureADUser |
Select-Object @(
@{L = "Name"; E = { $_.DisplayName}}
@{L = "Email"; E = { $_.UserPrincipalName}}
@{L = "Aliases"; E = { $_.ProxyAddresses -replace '^smtp:' -join ';' }}
)
这将使用PowerShell的功能使运算符自动处理数组的所有成员,然后加入结果,从而在每个代理地址的开头(^
)替换smtp:
.
This will replace smtp:
at the beginning (^
) of each proxyaddress, using PowerShell's ability to make operators automatically work on all members of an array, then join the results.
这篇关于使用Get-AzureADUser在PowerShell中从"SMTP:email@domain.com"中删除"SMTP"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!