【发布时间】:2020-10-21 22:17:48
【问题描述】:
下面这个可以正常工作,没有问题:
$properties = 'Name,msExchRemoteRecipientType,msExchRecipientDisplayType,msExchRecipientTypeDetails,proxyAddresses' -split ','
Get-ADUser -identity 'Lee.Xia' -Properties $properties |
Select-Object $properties
但是下面这个仅使用 SMTP 格式化电子邮件地址不起作用?
添加这一行:@{Label = 'Email Address'; Expression = {($_.proxyAddresses | Where-Object {($_ -like 'SMTP*') -and ($_ -notlike '*onmicrosoft.com') } | Sort-Object -CaseSensitive -Descending | ForEach-Object {$_.Split(':')[1]}) -join ', ' }}
所以它会是这样的:
$properties = 'Name,msExchRemoteRecipientType,msExchRecipientDisplayType,msExchRecipientTypeDetails,proxyAddresses' -split ','
Get-ADUser -identity 'Lee.Xia' -Properties $properties |
Select-Object $properties, @{Label = 'Email Address'; Expression = {($_.proxyAddresses | Where-Object {($_ -like 'SMTP*') -and ($_ -notlike '*onmicrosoft.com') } | Sort-Object -CaseSensitive -Descending | ForEach-Object {$_.Split(':')[1]}) -join ', ' }}
这是错误代码:
Select-Object : Cannot convert System.String[] to one of the following types {System.String, System.Management.Automation.ScriptBlock}.
At line:3 char:1
+ Select-Object $properties, @{Label = 'Email Address'; Expression = {( ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
+ FullyQualifiedErrorId : DictionaryKeyUnknownType,Microsoft.PowerShell.Commands.SelectObjectCommand
【问题讨论】:
标签: powershell active-directory powershell-4.0