Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm having difficulty running Exchange 2010 cmdlets through remote PowerShell sessions.

I start my local PowerShell session as Administrator and issue the following commands --

PS C:\Windows\system32> $mailcred = Get-Credential
PS C:\Windows\system32> $mailSession = New-PSSession -ComputerName MAILSRV -Credential $mailcred
PS C:\Windows\system32> Enter-PSSession $mailSession
[MAILSRV]: PS C:\Users\jdoe\Documents> Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010
[MAILSRV]: PS C:\Users\jdoe\Documents> hostname
MAILSRV
[MAILSRV]: PS C:\Users\jdoe\Documents> Get-ExchangeServer
Value cannot be null.    
Parameter name: serverSettings
    + CategoryInfo          : 
    + FullyQualifiedErrorId : System.ArgumentNullException,Microsoft.Exchange.Management.SystemConfigurationTasks.GetExchangeServer

[MAILSRV]: PS C:\Users\jdoe\Documents> get-mailbox
Value cannot be null.    
Parameter name: serverSettings
    + CategoryInfo          : 
    + FullyQualifiedErrorId : System.ArgumentNullException,Microsoft.Exchange.Management.RecipientTasks.GetMailbox

As you can see, none of the Exchange cmdlets are working. What could be the issue?

share|improve this question
    
Just to check, does the user you're running the session as have permission to run these cmdlets? i.e can you run them direct on the server without issue? –  Ben Pilbrow Apr 9 '12 at 22:00
    
Yup. They run fine on the server under the same account. Any type of remoting (invoke-command or interactive) fails. –  pk. Apr 10 '12 at 12:57
    
Try ImportSystemModules which loads registered modules in to the current runspace. Exchange cmdlets may not be automatically imported into the remote session/runspace. –  Bernie White Oct 3 '12 at 8:49

6 Answers 6

I had the same problem once. I think the solution was this:

$s=new-pssession -computername xxxxx
import-pssession -session $s

then add your snap-in, and run your commands

source: http://forums.veeam.com/viewtopic.php?f=2&t=7514

share|improve this answer
    
This would give me an implicitly remote session which isn't what I was going for. I'd really like to get interactive remoting working. For the purposes of troubleshooting this issue, I did try an implicit remote session and it failed in a different way. "Import-PSSession : Executing Get-Command command in remote session reported the following error: Exception has been thrown by the target of an invocation.." –  pk. Apr 12 '12 at 18:18

Did you try installing the Exchange Management Tools from the DVD and configure your workstation ?

share|improve this answer

I would suggest using remoting endpoint that is part of normal exchange installation. You can find more details here

I've used it successfully both with EX 2010 and EX 2013. It's supported way and it follows RBAC rules, so I would suggest using it rather than adding Exchange snappin to "normal" remoting endpoint.

share|improve this answer

The problem is that both machines should be in the same domain.

Also make sure you use the domain account, not the local one.

share|improve this answer

You're trying to connect to the default remoting endpoint on the Exchange Server and add the ps snapins from there. This is wrong. Replace your first 3 lines with this:

$mailcred = Get-Credential
$mailSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://MAILSRV/PowerShell/ -Credential $mailcred
Import-PsSession $mailSession

You don't have to enter the session, import it into the local session instead. From here on, you can use the Exchange-specific CmdLets locally. Also, some of the Exchange .Net types are installed with the Exchange Management Console, so this needs to be installed on your local computer if you want to do stuff with mailbox sizes (Exchange uses it's own types for size objects)

share|improve this answer
    
This is the right way to go, install the EMC on your management or work station for the PS extras. That way the local PS has access to the tools it needs when you connect. --- OR once you've done the EMC install use the Exchange Powershell that is installed directly. Right-click and run it as a management user if necessary. I use that all the time. –  Mark Jun 17 '13 at 19:47

You can do it like this, with import-pssesion and specifing the connectionURI & ConfigurationName.

PS U:\> $cred = Get-Credential
PS U:\> $session = New-PSSession -ConnectionUri http://Exchange01/powershell -ConfigurationName Microsoft.Exchange -Credential $cred
PS U:\> Import-PSSession $session
PS U:\> Get-Mailbox marius.davidsen

Name                      Alias                ServerName       ProhibitSendQuota                                                                                        
----                      -----                ----------       -----------------                                                                                        
Marius Davidsen           Marius.Davidsen      Exchange01       unlimited             

This requires that you do allow tcp port 80 in your firewall.

Using that session, you can also enter it like you wanted:

PS U:\> Enter-PSSession $session
[Exchange01]: PS> get-mailbox
[Exchange01]: PS> get-mailbox marius.davidsen

Name                      Alias                ServerName       ProhibitSendQuota                                                                                        
----                      -----                ----------       -----------------                                                                                        
Marius Davidsen           Marius.Davidsen      Exchange01       unlimited         
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.