![](/img/trans.png)
[英]Proxyaddresses added to the multivalued attribute not appearing on seperate lines
[英]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.