Anyway, I'm working on some Powershell scripts for work, and I'm stuck on something I thought would be fairly simple. Basically, there are some tasks that I need to perform on our Exchange server that would be great to script. I spent time writing a script that would connect me to our server (on the same domain), and run invoke-command for a few test commands. Once I get the test commands running, I can actually start writing the meat of the script.
For now however, I'm stuck just getting get-mailbox to return any information, which is really just me trying to test that things are working. See the three lines of test code here:
$mainSession = New-PSSession -ComputerName TheServerName
invoke-command -session $mainSession -ScriptBlock {add-pssnapin Microsoft.Exchange.Management.Powershell.Admin}
invoke-command -session $mainSession -ScriptBlock {get-mailbox}
I get a "psremotingtransportexception" exception with a "Job_Failure" error. What could this be? I know the snap-in and get-mailbox
commands work when I actually log-in to the server via remote-desktop and test them out. Assuming I can get get-mailbox
to function, I could actually perform the more complicated tasks I want to put in the script. The Exchange Server I'm connecting to is pretty old (2007?), so it's not that I'm using the wrong snap-in. Am I missing some credentials? Right now it's not asking me for any, but I tried adding the -credential flag and that didn't help either.
I'm super new to Powershell, so any help is greatly appreciated. Here is the exact error, apologies for the crap formatting:
Processing data for a remote command failed with the following error message: The WSMan provider host process did not return a proper response. A provider in the host process may have behaved improperly. For more information, see the about_Remote_Troubleshooting Help topic. + CategoryInfo : OperationStopped: (System.Manageme...pressionSyncJob:PSInvokeExpressionSyncJob) [], PSRemotingTransportException + FullyQualifiedErrorId : JobFailure
I should mention that I already tried increasing the shell MB size via set-item wsman:\localhost\shell\MaxMemoryPerShellMB 1024 -force
. My best guess is this has something to do with the -credential
flag but so far I haven't had any success with it.
Official support for remote Exchange administration with PowerShell was added in Exchange 2010, I believe.
It seems at least one person has found a way to make it work with Exchange 2007.
Sorry for the link-only answer, but the solution seems to be pretty involved, using impersonation, a special user account created for this purpose, script modules that have to be installed on the exchange server, etc.
Given this solution, I wonder if you could make it work more simply by using a PowerShell endpoint running as an exchange administrator. That would be cleaner than this mess. Basically you would create the endpoint, set the RunAsUser
, and then you could use StartupScript
to add the snapin. I really can't say if this will work though and I have no access to a Exchange 2007 environment where I could test it.