# Creating a persistent remote Exchange Shell session.

**URL:** <https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468>\
**Category:** PowerShell Help\
**Created:** [April 16, 2014, 2:08pm UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468 "2014-04-16T14:08:42Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![razz-tanwari](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@razz-tanwari](https://forums.powershell.org/u/razz-tanwari)\
**Post date:** [April 16, 2014, 2:08pm UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/1 "2014-04-16T14:08:42Z")

</div>

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

I followed the instructions [here](http://technet.microsoft.com/en-us/library/dd335083%28v=exchg.150%29.aspx) 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.

---

<div class="post-metadata">

**Author:** ![tore-groneng](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/tore-groneng/32/723_2.png) [@tore-groneng](https://forums.powershell.org/u/tore-groneng)\
**Post date:** [April 16, 2014, 8:52pm UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/2 "2014-04-16T20:52:48Z")

</div>

Hi,

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

Cherrie

Tore

---

<div class="post-metadata">

**Author:** ![donj](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/donj/32/137_2.png) [@donj](https://forums.powershell.org/u/donj)\
**Post date:** [April 17, 2014, 1:24am UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/3 "2014-04-17T01:24:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikefrobbins](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/mikefrobbins/32/272_2.png) [@mikefrobbins](https://forums.powershell.org/u/mikefrobbins)\
**Post date:** [April 17, 2014, 2:25am UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/4 "2014-04-17T02:25:51Z")

</div>

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.

µ

---

<div class="post-metadata">

**Author:** ![razz-tanwari](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@razz-tanwari](https://forums.powershell.org/u/razz-tanwari)\
**Post date:** [April 17, 2014, 2:32am UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/5 "2014-04-17T02:32:07Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![mikefrobbins](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/mikefrobbins/32/272_2.png) [@mikefrobbins](https://forums.powershell.org/u/mikefrobbins)\
**Post date:** [April 17, 2014, 2:33am UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/6 "2014-04-17T02:33:43Z")

</div>

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:

µ

---

<div class="post-metadata">

**Author:** ![mikefrobbins](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/mikefrobbins/32/272_2.png) [@mikefrobbins](https://forums.powershell.org/u/mikefrobbins)\
**Post date:** [April 17, 2014, 2:55am UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/7 "2014-04-17T02:55:44Z")

</div>

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:

µ

---

<div class="post-metadata">

**Author:** ![jeffrey-smith](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@jeffrey-smith](https://forums.powershell.org/u/jeffrey-smith)\
**Post date:** [April 17, 2014, 3:08am UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/8 "2014-04-17T03:08:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jeffrey-smith](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@jeffrey-smith](https://forums.powershell.org/u/jeffrey-smith)\
**Post date:** [April 17, 2014, 3:08am UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/9 "2014-04-17T03:08:39Z")

</div>

Um, OK. Here’s the link:

---

<div class="post-metadata">

**Author:** ![jeffrey-smith](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@jeffrey-smith](https://forums.powershell.org/u/jeffrey-smith)\
**Post date:** [April 17, 2014, 3:09am UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/10 "2014-04-17T03:09:18Z")

</div>



---

<div class="post-metadata">

**Author:** ![jeffrey-smith](https://avatars.discourse-cdn.com/v4/letter/j/57b2e6/32.png) [@jeffrey-smith](https://forums.powershell.org/u/jeffrey-smith)\
**Post date:** [April 17, 2014, 3:09am UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/11 "2014-04-17T03:09:47Z")

</div>

OK, I obviously have no idea how to use the markup here to add a link:

[http://blogs.msdn.com/b/powershell/archive/2006/04/30/how-powershell-formatting-and-outputting-really-works.aspx](http://blogs.msdn.com/b/powershell/archive/2006/04/30/how-powershell-formatting-and-outputting-really-works.aspx)

---

<div class="post-metadata">

**Author:** ![razz-tanwari](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@razz-tanwari](https://forums.powershell.org/u/razz-tanwari)\
**Post date:** [April 17, 2014, 8:00pm UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/12 "2014-04-17T20:00:19Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![razz-tanwari](https://avatars.discourse-cdn.com/v4/letter/r/977dab/32.png) [@razz-tanwari](https://forums.powershell.org/u/razz-tanwari)\
**Post date:** [April 17, 2014, 8:48pm UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/13 "2014-04-17T20:48:30Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:52pm UTC](https://forums.powershell.org/t/creating-a-persistent-remote-exchange-shell-session/2468/14 "2024-05-16T20:52:12Z")

</div>


