【发布时间】:2021-06-21 13:27:45
【问题描述】:
我正在尝试使用 get-mailpublicfolder 命令提取与我们的某些 Exchange 2010 公用文件夹关联的 SMTP 地址列表
虽然我可以提取 WindowsEmailAddress 和 EmailAddresses 值,但后者包含我想排除的 X400 地址。
我能找到的与此相关的最接近的是以下链接中列出的代码
https://unlockpowershell.wordpress.com/2010/01/27/powershell-get-mailbox-display-smtp-addresses/
但这似乎只适用于 Get-Mailbox,因为以下代码返回以下错误
$data=Get-MailPublicFolder -Identity $id |select-object WindowsEmailAddress,@{Name="EmailAddresses";Expression={$_.EmailAddresses}|Where-Object {$_.PrefixString -ceq "smtp:"}}| ForEach-Object {$_.SmtpAddress}
Select-Object : Key "Expression" has illegal type System.Management.Automation.PSObject; expected types are {System.Str
ing, System.Management.Automation.ScriptBlock}.
At C:\Temp\FindAllEmailAdresses_v1.ps1:33 char:56
+ $data=Get-MailPublicFolder -Identity $id |select-object <<<< WindowsEmailAddress,@{Name="EmailAddresses";Expression=
{$_.EmailAddresses}|Where-Object {$_.PrefixString -ceq "smtp:"}}| ForEach-Object {$_.SmtpAddress}
+ CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
+ FullyQualifiedErrorId : DictionaryKeyIllegalValue1,Microsoft.PowerShell.Commands.SelectObjectCommand
Select-Object : Key "Expression" has illegal type System.Management.Automation.PSObject; expected types are {System.Str
ing, System.Management.Automation.ScriptBlock}.
或
$data=Get-MailPublicFolder -Identity $id |select WindowsEmailAddress,@{Name="EmailAddresses";Expression={$_.EmailAddresses}|Where-Object {$_.PrefixString -ceq "smtp:"}}
+ $data=Get-MailPublicFolder -Identity $id |select <<<< WindowsEmailAddress,@{Name="EmailAddresses";Expression={$_.
ilAddresses}|Where-Object {$_.PrefixString -eq "smtp:"}}
+ CategoryInfo : InvalidArgument: (:) [Select-Object], NotSupportedException
+ FullyQualifiedErrorId : DictionaryKeyIllegalValue1,Microsoft.PowerShell.Commands.SelectObjectCommand
Select-Object : Key "Expression" has illegal type System.Management.Automation.PSObject; expected types are {System.
ing, System.Management.Automation.ScriptBlock}.
At C:\Temp\FindAllEmailAdresses_v1.ps1:31 char:49
是否可以只提取 SMTP 地址,还是我也坚持提取 x400 地址? 提前致谢
编辑
根据答案,我已将代码更改为以下内容,并且可以进行一项更改,即从 -ceq "smtp:" 部分中删除冒号,因为将其保留在适当的位置会导致电子邮件地址没有被退回。请注意,这是我的错误,而不是 Dougs,因为他们只是基于我之前提供的代码。
$expression = {$_.EmailAddresses | Where-Object {$_.PrefixString -ceq "smtp"} | ForEach-Object {$_.SmtpAddress}}
$selectprops = 'WindowsEmailAddress',
@{Name="EmailAddresses"; Expression=$expression}
$data = Get-MailPublicFolder -Identity $id | Select-Object $selectprops
【问题讨论】:
标签: powershell exchange-server powershell-2.0 exchange-server-2010