Creating a persistent remote Exchange Shell session.

This topic contains 12 replies, has 5 voices, and was last updated by Profile photo of Damel Damel 3 years ago.

  • Author
    Posts
  • #14602
    Profile photo of Damel
    Damel
    Participant

    I am running a Powershell script that contains Exchange Shell cmdlets.

    I followed the instructions here to setup a remote connection to Exchange Shell.

    However, the created connection appears to only return output for only the first command.

    My simple test script :

    Get-TransportConfig | Select Identity, MaxRecipientEnvelopeLimit
    Get-TransportConfig | Select Identity, MaxReceiveSize

    Only the first command regarding MaxRecipientEnvelopeLimit returns a value. The next command does not return anything. When I switch the commands around, the same happens, only the 1st command runs.

    Any help is appreciated.

  • #14608
    Profile photo of Tore Groneng
    Tore Groneng
    Participant

    Hi,

    Maybe you nede to post the contents of your function. Hard to help without it

    Cherrie

    Tore

  • #14612
    Profile photo of Don Jones
    Don Jones
    Keymaster

    There are some known problems I've heard of regarding Exchange and implicit remoting. I'll see if I can point someone to look at this, who might have more experience.

  • #14614
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    I can confirm this is an issue, although I can't explain it. I ran the commands directly on a server with Exchange 2010 SP3 to eliminate any remoting issues. Server is running Windows Server 2008 R2 with SP1. PowerShell version is 2.

    Example of Reported Issue

    µ

  • #14615
    Profile photo of Damel
    Damel
    Participant

    @Tore Groneng: My script has no functions, it is exactly what I have quoted in my 1st post 🙂

    @Don Jones: Thanks for the help.

    @mike F Robbins: Yes, you hit it spot on, this is what I get as well. I am running Exchange 2013 on Server 2012. Powershell Version 3. So apparently the issue persists in later versions..

    Interestingly, if I try another set of Exchange cmdlets, it works to a certain extent. Take for example,

    Get-RemoteDomain | select identity, DeliveryReportEnabled
    Get-PopSettings | fl -property LoginType

    It outputs perfectly fine. But when rearrange the positioning and add in other cmdlets, everything goes awry again.

  • #14619
    Profile photo of Jeffrey Smith
    Jeffrey Smith
    Participant

    Um, OK. Here's the link:

  • #14620
    Profile photo of Jeffrey Smith
    Jeffrey Smith
    Participant

  • #14621
    Profile photo of Jeffrey Smith
    Jeffrey Smith
    Participant
  • #14625
    Profile photo of Damel
    Damel
    Participant

    Okay I sort of solved it, although I am not sure if this is the right method.

    I piped the cmdlets to "Select" instead of "Format-List", and it worked.

  • #14616
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    Jut saw that Rob Campbell (@mjolinor) posted on twitter that it's an issue with the default formatting. Piping it to Format-List shows the properties:

    µ

  • #14617
    Profile photo of Mike F Robbins
    Mike F Robbins
    Participant

    It's because the first command sets the pipeline up for only the Identity and MaxRecipientEnvelopeLimit properties. When the second command runs, the pipeline doesn't know anything about the MaxReceiveSize property so only the Identity property results are displayed for that command (the second one). You could jam any two commands together and have the same issue.

    Notice the handles property doesn't show up in the results of this script and the second row for the id property is blank:

    µ

  • #14618
    Profile photo of Jeffrey Smith
    Jeffrey Smith
    Participant

    Here's a good old article from Jeffrey Snover himself that explains why this is:

  • #14624
    Profile photo of Damel
    Damel
    Participant

    @jeffrey Smith : Thanks for the link, will try to digest it.

    @mike F Robbins : Thanks for the explanation. But now I ran into another problem.

    Format-List will conflict with some of the cmdlets that already use Format-List. Output formatting is hard to handle properly =/

    For instance, this script will not work when I execute it with Format-List. ( ./script1 | fl )
    It will spew errors.

    "Maximum size of received emails : \r\n"
    Get-TransportConfig | Select Identity, MaxReceiveSize 
    "\r\n"
    
    "Password Policy Settings : \r\n"
    Get-ActiveSyncMailboxPolicy |  fl -property DevicePasswordHistory
    Get-ActiveSyncMailboxPolicy |  fl -property DevicePasswordExpiration
    "\r\n"
    

    note: I have replaced the escape character with a \ instead.

You must be logged in to reply to this topic.