Making calls to Exchange Management Shell from a remote Linux server

Don't ask why I have to call remotely using winexe -- it's a customer requirement ;-)

Logged onto the Linux shell, the following command (to a standard powershell) is successful as a test to receive Forest details:

/usr/bin/winexe -U dallasray/administrator%somePassword // "powershell.exe \"Get-AdForest 'dallasray' | ConvertTo-JSON\""

But I need to call an Exchange Management Shell in order to auto export various mailboxes. To ensure my command works I ran the shell on the server and issued with success the following:

New-MailboxExportRequest -Mailbox "my_testuser" -FilePath "\\server\share\my_testuser.pst"

So my initial attempt to combine these 2 techniques fails. The failed command follows:

/usr/bin/winexe -U dallasray/administrator%somePassword // "powershell.exe -noexit -command \". \'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1\'; Connect-ExchangeServer -auto -ClientApplication:ManagementShell New-MailboxExportRequest -Mailbox \"my_testuser\" -FilePath \"\\server\share\my_testuser.pst\""

Specifically the error returned is:

ERROR: Cannot open control pipe - NT_STATUS_INVALID_PARAMETER
Dallas SmetterSolution EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dallas SmetterSolution EngineerAuthor Commented:
The following works nicely when run from a dos prompt locally...

C:\Users\s-idauto>PowerShell.exe -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; New-MailboxExportRequest -Mailbox "my_testuser" -FilePath "\\deonetapp01\userarchive$\my_testuser.pst"

but I want a version that I can run remotely from winexe, so I tried escaping quotes like

/usr/bin/winexe -U dallasray/administrator%somePassword // "PowerShell.exe -command \". \'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1\'; Connect-ExchangeServer -auto;"

but that yields an error of "ERROR: Cannot open control pipe - NT_STATUS_INVALID_PARAMETER"
Jian An LimSolutions ArchitectCommented:
i never use winexe before

can you try to do remote call instead of calling the powershell directly? (from my memory it use .netframework on certainthings )

to connect remotely,

you need to define your session and Import-PSSession $Session
Dallas SmetterSolution EngineerAuthor Commented:
After much troubleshooting I found that this is a bug in winexe when run against Server 2012 R2. I switched to using a server that is plain Server 2012 and it works. The bug is documented at

Thank you for your reply!

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Dallas SmetterSolution EngineerAuthor Commented:
I researched and found that there's an open bug in Winexe related to Server 2012 R2. I started running against a non-R2 box and it works.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.