ExpandProperty dosent work

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
Supervisor
Posts: 2
Last visit: Thu Jul 09, 2020 5:12 am

ExpandProperty dosent work

Post by Supervisor »

Product, version and build: 5.4.138_032917
32 or 64 bit version of product: PowerShellStudio 2017
Operating system: Server 2016
32 or 64 bit OS: 64
PowerShell Version: 5.0


Cannot Expand and Select specify properties
This is a part of my script and i would like to got the Property/Member "Major" but the output ist null:

PS Remoting to a Exchange Server is successful

$RemoteHost = (Get-PSSession).Computername
$Exchange_Version = (Get-ExchangeServer -Identity $RemoteHost | select -ExpandProperty AdminDisplayVersion).Major

In the EMS it works, so what can i do ?

Major:
Minor:
Build:
Revision:
FilePatchLevelDescription:
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: ExpandProperty dosent work

Post by davidc »

[TOPIC MOVED TO THE POWERSHELL FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ExpandProperty dosent work

Post by jvierra »

It is not clear what you are trying to do. You are stating that you are remoting but are getting the session then trying to us it locally.

The remote session may not be the same system as the exchange server system.

Also note that Get-PsSession may return more than one session.
User avatar
Supervisor
Posts: 2
Last visit: Thu Jul 09, 2020 5:12 am

Re: ExpandProperty dosent work

Post by Supervisor »

First in PowerShellStudio connect to a Exchange Server via PS Remoting, so that is successful.... The Exchange Commands are available....

Implicit Remoting:

$server = "ServerName"
$Session = New-PSSession -Name "Exchange" -ConfigurationName Microsoft.Exchange -ConnectionUri http://$server/PowerShell/ -Authentication Kerberos
Import-PSSession $Session -DisableNameChecking

Now the Problem: (I would like to check the PS Session -> Exchange Version (Major)14 or ...)

$Version = (Get-ExchangeServer -Identity ((Get-PSSession).Computername) | select -ExpandProperty AdminDisplayVersion).Major
Write-host "Version ----> $Version"

The output is null but a session is available (Get-PSSession).Computername -> Name of a ExchangeServer

The same Command in EMS:

Version -----> 14



Is there a failure in the Remoting or missing any assemblies ?
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: ExpandProperty dosent work

Post by jvierra »

Your insistence on doing everything on one line is getting in the way of you understanding what is happening.
Jut get the object and select the property. There is no need to do all of that expanding.

Inspect the results of getting each object until you see how the object works.

Remoted objects get serialized and can behave oddly when you try to get fancy.
This topic is 7 years and 1 week old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked