Connecting to a remote Exchange 2010 Organization using Remote PowerShell

In this blog post I wanted to show you how you can connect to an Exchange 2010 server in a remote organization using Remote PowerShell (Windows PowerShell 2.0) running on a Windows client/server. In this specific example, I’ve installed Windows PowerShell V2 CTP3 and WSMan on a Windows 2008 server).

First step is to launch Windows PowerShell. Then we will create a variable storing the credentials for the administrator in the remote Exchange 2010 organization. We do so using the below command:

$UserCredential = Get-Credential

image

Now enter the credentials of the administrator account from the remote Exchange 2010 organization.

image 

We will now connect to the remote Exchange 2010 organization by specifying the name of an Exchange 2010 server in that specific organization. In this particular example we use the following command:

$Session = New-PSSession –ConfigurationName Microsoft.Exchange –ConnectionUri https://E2K10EX01/PowerShell/ –Credential $UserCredential

image

Note
In order to connect to the remote Exchange 2010 organization, your local machine must either trust the certificate on the specific Exchange 2010 server you connect to or you must use the  -SessionOption $SkipCertificate parameter in the above command.

We now need to import the server-side PowerShell session which is done with the following command:

Import-PSSession $Session

image

The cmdlets etc. will now be imported to the client-side session. You will probably get a few warning because some of the cmdlet’s already are available in the client-side session. as can be seen below.

image

Now let’s try to issue a command against the remote Exchange organization. In the below figure, I retrieve details for an Exchange 2010 server in the remote Exchange organization.

image

Let’s try to create an Exchange object and then manipulate it afterwards. Below I create a new distribution group and then add a user mailbox to it.

image

We’ll now switch to an Exchange 2010 Management Console in the remote org and verify the distribution group were created properly and that the user mailbox were added to it.

image

When finished administering the remote Exchange 2010 organization, you can disconnect the the client-side session using:

Remove-PSSession $Session

Yes Windows PowerShell in Exchange 2007 was pretty cool, but it simply rocks in Exchange 2010! 🙂

 

– Henrik Walther

About The Author

2 thoughts on “Connecting to a remote Exchange 2010 Organization using Remote PowerShell”

  1. Sreejith Sasidharan

    Hi Henrik i am trying to run the command as shown below but it does not work with $SkipCertificate

    $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://xyz/Powershell/ -SessionOption $SkipCertificate

    Error
    ——

    New-PSSession : Cannot validate argument on parameter 'SessionOption'. The argu
    ment is null. Supply a non-null argument and try the command again.
    At line:1 char:125
    + $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
    https://xyz/Powershell/ -SessionOption <<<< $SkipCertificate
    + CategoryInfo : InvalidData: (:) [New-PSSession], ParameterBindi
    ngValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.Power
    Shell.Commands.NewPSSessionCommand

    Can you please help.

    Thanks a lot

  2. Jean-Philippe Prime

    Hi Sreejith,

    If you don't have found the solution to create $SkipCertificate …

    The solution:
    Before the $Session=
    type this
    $SkipCertificate = New-WSManSessionOption -SkipCACheck -SkipCNCheck – SkipRevocationCheck

    Thanks

Leave a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Scroll to Top