PowerShell Remoting w/ Exchange 2010: Value cannot be null

exchange-2010powershell

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?

Best 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)