-ExpandProperty does not show all properties via Remote PowerShell
When I run the following code in Exchange PowerShell on the Exchange server, it shows all the properties:
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 local machine via
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri ("http://" + $Server + "/PowerShell/") -Authentication Kerberos
Import-PSSession $Session
and run the same code as only:
PS> Get-Mailbox Testeria | select -ExpandProperty EmailAddresses smtp: Tester_IA@contoso.com SMTP: TesterIA@contoso.com smtp: TesterIA@outlook.contoso.com
How do you understand this behavior? How do I get all properties via Remote PowerShell?
PSVersion on local machine - 5.1.14409.1005
PSVersion on Exchange Server 4.0
source to share
This is probably because the results are deserialized when objects are accessed via PSRemoting. You can see that this is the case by looking at the TypeName of the resulting object by querying it for Get-Member
. You will see Deserialized prefixed with Type:
Objects that are "Deserialized". the prefix in their type names are property packages that contain a deserialized public representation of the property of the corresponding remote, live objects. As you can see in the Get-Member output, these property packages do not expose any methods other than ToString (), because usually methods cannot be called in a remote session (for example, System.Diagnostics.Process.Kill () cannot act on a remote process ). Likewise, setting and retrieving property bag values does not execute any code (for example, the WorkingSet Deserialized.System.Diagnostics.Process.WorkingSet property is just a snapshot and is not updated when the remote process uses more memory).
My guess is that the property EmailAddresses
is a Script property, which means it executes the Script when called to get its helper properties. When you retrieve an object via Remoting, you lose the ability to execute this script.
Unfortunately, I don't have an Exchange system to test this at the moment.
source to share