powershell - -ExpandProperty 不通过远程 PowerShell 显示所有属性

标签 powershell exchange-server

当我在 Exchange 服务器上的 Exchange PowerShell 中运行以下代码时,它会显示所有属性:

PS> Get-Mailbox Testeria | select -ExpandProperty EmailAddresses

SmtpAddress        : Tester_IA@contoso.com
AddressString      : Tester_IA@contoso.com
ProxyAddressString : smtp:Tester_IA@contoso.com
Prefix             : SMTP
IsPrimaryAddress   : False
PrefixString       : smtp

SmtpAddress        : TesterIA@contoso.com
AddressString      : TesterIA@contoso.com
ProxyAddressString : SMTP:TesterIA@contoso.com
Prefix             : SMTP
IsPrimaryAddress   : True
PrefixString       : SMTP

SmtpAddress        : TesterIA@outlook.contoso.com
AddressString      : TesterIA@outlook.contoso.com
ProxyAddressString : smtp:TesterIA@outlook.contoso.com
Prefix             : SMTP
IsPrimaryAddress   : False
PrefixString       : smtp

But when I try to use Remote PowerShell on the local machine via

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ("http://" + $Server + "/PowerShell/") -Authentication Kerberos
Import-PSSession $Session

并运行相同的代码,它只显示这个:

PS> Get-Mailbox Testeria |选择 -ExpandProperty 电子邮件地址

smtp:Tester_IA@contoso.com
SMTP:TesterIA@contoso.com
smtp:TesterIA@outlook.contoso.com

如何理解这种行为?如何通过远程 PowerShell 获取所有属性?

本地机器上的 PSVersion 是 5.1.14409.1005

Exchange Server 上的 PSVersion 为 4.0

最佳答案

这可能是因为当您通过 PSRemoting 访问对象时,结果会被反序列化。您可以通过将结果对象的 TypeName 传送到 Get-Member 来查看它的情况。 .您将看到反序列化以类型为前缀:

Objects that have the "Deserialized." prefix in their type names are property bags that contain a deserialized representation of public properties of the corresponding remote, live objects. As you can see in the output of Get-Member those property bags don’t expose any methods except ToString(), because usually methods cannot be invoked in the remote session (for example, System.Diagnostics.Process.Kill() can’t act on a remote process). Similarly setting and getting property values of the property bags doesn’t execute any code (for example WorkingSet property of Deserialized.System.Diagnostics.Process.WorkingSet is only a snapshot and doesn’t get updated when the remote process uses more memory).


  • https://blogs.msdn.microsoft.com/powershell/2010/01/07/how-objects-are-sent-to-and-from-remote-sessions/

  • 我的假设是 EmailAddresses property 是一个脚本属性,这意味着它在调用以获取其子属性时执行脚本。当您通过远程处理检索对象时,您将失去执行此脚本的能力。

    不幸的是,我目前没有 Exchange 系统来验证这一点。

    关于powershell - -ExpandProperty 不通过远程 PowerShell 显示所有属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44824972/

    相关文章:

    c# 远程 powershell 创建 AD/Exchange 用户帐户并修改

    ssl - Exchange 服务器通配符证书错误

    sharepoint - 将 SharePoint 警报发送到 Exchange 中的公用文件夹

    php - 使用 PHP mail() 函数通过 Exchange 发送电子邮件时出现延迟(使用 sendmail 作为中继)

    Azure表存储: a script to populate new column for existing tables

    powershell - 如何遍历文件并使用PowerShell重命名?

    powershell - 如何在Word.Application中设置SaveAs()对话框的参数?

    c# - 从代码隐藏在 Exchange 服务器上创建公用文件夹

    powershell - 使用命令行检查nuget包是否存在

    string - 将字符串转换为 csv Powershell