获取用户的proxyaddresses属性

时间:2019-12-24 13:34:41

标签: powershell

我有下面的Powershell代码行,我正在提取用户代理地址值。我需要如下所示的所有smtp和/或SMTP值。

Get-ADUser -Filter * -Properties proxyaddresses | Select-Object Name, @{L = "ProxyAddresses"; E = { $_.ProxyAddresses -join ";"}} | Export-Csv -Path c:\temp\proxyaddresses.csv -NoTypeInformation

我的输出:

"Name","ProxyAddresses"
"John T","sip:john@contoso.com;smtp:john@contoso1.com;SMTP:john@contoso.com;smtp:john@contoso1.com;X400:C=US;A= ;P=ORG;O=Exchange;S=T;G=John;"

我想要的输出:

"Name","ProxyAddresses"
"John T","smtp:john@contoso1.com;SMTP:john@contoso.com;smtp:john@contoso1.com"

1 个答案:

答案 0 :(得分:0)

由于ProxyAddresses属性将被解释为字符串的集合,因此可以使用reconsidered。这里最简单的选项是-like-match

Get-ADUser -Filter * -Properties proxyaddresses |
    Select-Object Name, @{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -match '^smtp:') -join ";"}}
# Or
Get-ADUser -Filter * -Properties proxyaddresses |
    Select-Object Name, @{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -like 'smtp:*') -join ";"}}

-like-match不区分大小写。您可以在区分大小写的版本的运算符名称后附加c。当寻找以SMTP:开头的主要smtp地址时,这可能会很有用。在这种情况下,您可以使用:

Get-ADUser -Filter * -Properties proxyaddresses |
    Select-Object Name, @{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -cmatch '^SMTP:') -join ";"}}
# OR

Get-ADUser -Filter * -Properties proxyaddresses |
    Select-Object Name, @{L = "ProxyAddresses"; E = { ($_.ProxyAddresses -clike 'SMTP:*') -join ";"}}
相关问题