簡體   English   中英

獲取用戶的proxyaddresses屬性

[英]Getting the proxyaddresses attribute of users

我有以下一行 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"

由於ProxyAddresses屬性將被解釋為字符串集合,因此您可以使用比較運算符 這里最簡單的選項-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 ";"}}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM