[英]Pulling User Object's Primary SMTP from ProxyAddresses
I have a PS script that is pulling Employee IDs from a CSV file that I update every morning that I get from HR just to make sure the automation is running correctly by adding/changing their email, extensionAttribute 1, and the ProxyAddresses.我有一个 PS 脚本,它从 CSV 文件中提取员工 ID,我每天早上从 HR 处更新该文件,以确保通过添加/更改 email、extensionAttribute 1 和 ProxyAddresses 来正确运行自动化。 I would like it to only check for the Primary SMTP instead of all ProxyAddresses but am having trouble.
我希望它只检查主 SMTP 而不是所有 ProxyAddresses,但我遇到了麻烦。
Import-Csv "C:\temp\HRfeed101519.csv" | foreach {Get-ADUser $_.EmpID -Properties * | fL mail, extensionattribute1, Proxyaddresses}
The ProxyAddresses
field identifies the PrimarySMTPAddress
with the SMTP:
tag. ProxyAddresses
字段使用SMTP:
标记标识PrimarySMTPAddress
。 Therefore, you can query for that specifically and output it as a calculated property.因此,您可以专门查询它并将 output 作为计算属性。
Get-ADUser $_.EmpID -prop ProxyAddresses,Mail,ExtensionAttribute1 |
Select-Object Mail,ExtensionAttribute1,ProxyAddresses,
@{Name='PrimarySMTPAddress';Expression={$_.ProxyAddresses -cmatch '^SMTP:' -creplace 'SMTP:'}}
-cmatch
and -creplace
perform case-sensitive regex matching. -cmatch
和-creplace
执行区分大小写的正则表达式匹配。
Note: The default table display of the output may not show all of the properties and values due to collection size stored in ProxyAddresses
.注意:由于
ProxyAddresses
中存储的集合大小,output 的默认表格显示可能不会显示所有属性和值。 You can pipe your output to Format-List
to see all properties, but do not store the Format-List
output in a variable.您可以 pipe 您的 output 到
Format-List
以查看所有属性,但不要将Format-List
output 存储在变量中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.