Exchange Remoting missing information

I'm trying to build a script that will get information from Exchange

Here's an example to my problem:

When I run the $exServer = get-ExchangeServer command on an Exchange server, All values are within $exServer

When I write: $exServer.AdminDisplayVersion
I get the result:

Major : 15
Minor : 0
Build : 1156
Revision : 6
FilePatchLevelDescription :


When I write: $exServer.AdminDisplayVersion.Major

I get the result: 15


And when I try to make it remoting
The result is different:

$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri Exchange_Server_Name/PowerShell -Authentication Kerberos 
$exServer = Invoke-Command -Session $session -ScriptBlock {Get-ExchengeServer}


When I write: $exServer.AdminDisplayVersion

I get the result: Version 15.0 (Build 1156.6)

There is no major at all

(And this is just an example)


I would highly appreciate the help, I have been trying to solve this for quite some time

  • That is because the value returned is the full version info, not the split / array.

    On real Exchange it does the parsing for you. I've personally never looked for this sort of break out. The full version string is all I've ever needed.

    So, though it is not broken out, it is all there.

    Major.Minor Build.Revision
    Version 15.1 (Build 669.32)

    So, if you are looking to do this as a array as if you were on the Exchange server
    remotely, then you need to manipulate that string to break it apart.

    Something like.

    $Counter = 0
    'Major : ','Minor : ','Build : ','Revision : ' | % {$Counter += 1
    $_ + [regex]::Matches((Get-ExchangeServer).AdminDisplayVersion, "\d+[?!*\d+]|[\d+[?!*\d]").value[$Counter -1]

    Major : 15
    Minor : 1
    Build : 669
    Revision : 32

    Now, I used kind of a funky ForLoop here and I could have just done this:

    'Major : ' + [regex]::Matches((Get-ExchangeServer).AdminDisplayVersion, "\d+[?!*\d+]|[\d+[?!*\d]").value[0]
    'Minor : ' + [regex]::Matches((Get-ExchangeServer).AdminDisplayVersion, "\d+[?!*\d+]|[\d+[?!*\d]").value[1]
    'Build : ' + [regex]::Matches((Get-ExchangeServer).AdminDisplayVersion, "\d+[?!*\d+]|[\d+[?!*\d]").value[2]
    'Revision : ' + [regex]::Matches((Get-ExchangeServer).AdminDisplayVersion, "\d+[?!*\d+]|[\d+[?!*\d]").value[3]

    Major : 15
    Minor : 1
    Build : 669
    Revision : 32

    But I wanted to not have to repeat the RegEx multiple individual times.

    Yet, still, I am unsure why this is a thing for you, but I am sure you have your reasons. I know this does not explain why the cmdlet parse differently via local vs remote, but again, you are not missing any data. You are just not getting the same display.
  • In reply to postanote:

    thank you for the answer

    The purpose of the script I want to build, is to check the Exchange version, and according to the result run queries and get information.

    By the way, this is the first serious script I'm building

    Since the script performs different tests on many servers, the goal is to run on one of the servers and get all the information from all the servers

    I have seen some scripts that perform integrity checks on Exchange servers

    for example:

    I tried to learn from these scripts how to perform tests on Exchange servers, but they seem to work only from the Exchange Management Shell

    Because my script should run from any server or computer in the domain, I'm trying to figure out how I run commands like get-ExchangeServer and others, not from Exchange Management Shell

    Your answer does indeed answer the specific example I brought, but I would be happy if there is a solution that allows Exchange commands to be run remotely

  • In reply to MTZ:

    No worries.

    The response I was provided running a script remotely to the Exchange server.
    I always default to the PoSH-ISE, for all things, even on the Exchange server.

    On my Exchange servers, I just bring the Exchange cmdlets into the PoSH ISE using...

    Add-PSSnapin -Name *Exchange*

    ...then hit the 'Refresh' button on the Command Tab to populate the list with the Exchange cmdlets.

    Your original post, showed you using -Authentication Kerberos only.

    When you do it that way, you rare saying, use the current logged on credentials. I've always made teh habit to explicitly provide the needed Exchange Admin creds.

    Your post does this:

    $ExchangeSession = New-PSSession -ConfigurationName 'Microsoft.Exchange' `
    -ConnectionUri ('YourExchangeServerFQDN/PowerShell') `
    -Authentication Kerberos

    When I would suggest doing this:

    # This gets the current user domain and username
    $CredsAdmin = Get-Credential -Credential "$env:USERDOMAIN\$env:USERNAME"
    # but you can change the above to a specific domain\username

    $ExchangeSession = New-PSSession -ConfigurationName 'Microsoft.Exchange' `
    -ConnectionUri ('YourExchangeServerFQDN/PowerShell') `
    -Authentication Kerberos -Credential $CredsAdmin

    # This proxies the Exchange cmdlets to the localhost
    Import-PSSession $ExchangeSession

    # No Invoke-Command required for this method, just use the cmdlets

    Your Exchange code goes here
    Just use the Exchange commands as if you are on the Exchange Server, though the display from some of the responses will be a bit different as noted above, but the data are still correct.




    # This drops all the above from the localhost.
    Get-PSSession | Remove-PSSession

  • In reply to postanote:

    I'll try to work with the data I get in this way
  • In reply to MTZ:

    No worries.
    Proxying the cmdlets, allows you to treat the server being proxied to, to function like the source.
    So, that make things much easier.

    I pulled down the script you referenced above and played with it and I was able to get it to run without the use of the EMC by using my method above...

    You should be able to just add this to the top of the script (just put it below the param block) you downloaded, as it then loads the environment the script needs, as long as you run the script on the ExchangeServer. The below, forces a skip of the code block... # 1.1 Check Exchange Management Shell, attempt to load

    $ExchangeServerName = ''
    $CredsAdmin = Get-Credential -Credential "contoso\ExchangeAdminName"

    $ExchangeSession = New-PSSession -ConfigurationName 'Microsoft.Exchange' `
    -ConnectionUri ("http://$ExchangeServerName/PowerShell") `
    -Authentication Kerberos -Credential $CredsAdmin
    Import-PSSession $ExchangeSession

    I have not tried to run the script remotely, as that requires modifying the code directly, due to some of the aspects of the script.