• RSS
  • Twitter
  • FaceBook

Henrik Walther Blog RSS

All Blogs  »  Henrik Walther Blog  »  News  »  Blog article: Connecting to a remote Exchange 2010 Organization using Remote PowerShell

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

8 Responses to “Connecting to a remote Exchange 2010 Organization using Remote PowerShell”

  1. cheikh siby Says:

    April 8th, 2010 at 1:34 pm

    How do I this with Exchange 2007?

    I’m trying to manage my exchange 2007 using remote powershell but I get this below error all the times. I have powershell 2.0 and powershell remoting is enabled. Note that it doesn’t work even if I specified domain controller.

    PS C:\> Invoke-Command -Session $session {Get-exchangeserver}
    An Active Directory error 0×80072020 occurred while searching for domain contro
    llers in domain hcmny.com: An operations error occurred.
    + CategoryInfo : NotSpecified: (0:Int32) [Get-ExchangeServer], AD
    TransientException
    + FullyQualifiedErrorId : 3B4FD592,Microsoft.Exchange.Management.SystemCon figurationTasks.GetExchangeServer

  2. Henrik Walther Says:

    April 8th, 2010 at 1:37 pm

    Altough Exchange 2007 supports PowerShell 2.0 it doesn’t support the remote PowerSehll feature so what you’re trying to do is not possible.

  3. Navin Shetty Says:

    May 11th, 2010 at 12:23 pm

    Thanks for the info, I really appreciate your work

  4. Henrik Walther Says:

    May 12th, 2010 at 1:40 am

    Thanks Navin! :)

  5. anuj Says:

    August 17th, 2010 at 8:07 am

    simple gr8 work keep it up
    regards
    Anuj

  6. rahul Says:

    December 13th, 2010 at 8:56 am

    wow that is what i am looking for thanks keep posting :)

  7. Ryan Kasten Says:

    December 16th, 2010 at 9:11 am

    Very helpful article that got me pointed in the right direction. I had trouble with the Basic Authentication mechanism, so I enabled Windows Authentication on the remote server via the following path: IIS Manager->(Machine)->Sites->Default Web Site->PowerShell, Authentication feature

    I also had trouble with the -SessionOption $SkipCertificate parameter, so I imported the SSL Certificate into my Trusted Root Certification Authorities, and now it works seamlessly. (NB: This is a demo environment - blindly importing untrusted certs is not a recommended practice. I knew where this cert came from, because I made it.)

    Thank you for this :)

  8. guide Says:

    March 20th, 2012 at 10:45 pm

    Good info. Lucky me I discovered your site by accident (stumbleupon).
    I have saved it for later!

Leave a Reply


Receive all the latest articles by email!

Receive Real-Time & Monthly MSExchange.org article updates in your mailbox. Enter your email below!
Click for Real-Time sample & Monthly sample

Become an MSExchange.org member!

Discuss your Exchange Server issues with thousands of other Exchange experts. Click here to join!