Wednesday 3 March 2010

Using Remote Powershell to administer Exchange 2010

So you fancy administering your Exchange 2010 Org without installing the Exchange Management Tools on your workstation huh? Read on..

First you must ensure you have WinRM and Powershell 2.0 on your workstation. This is present by default in Windows 2008 R2 and Windows 7, however for XP, Vista or Server editions of 2003 or 2008 you can download the required Windows Management Framework install files here.

Once installed fire up Powershell. It doesn't have to be run in Administrator mode for this to work. To make things easy lets cache our credentials

$user = Get-Credential

This binds the credentials we supply to be user later using the $user.

Once that is done we will bind a new session to a variable. I am performing the following over HTTP due to constraints in my lab.

$session = New-PSSession -configurationname -connectionuri http://yourcasserver/powershell -credential $user

The above binds the New-PSSession cmdlet with our settings to $session, you can also see we supply our credentials for this using our existing $user variable we have already made.

We can now import the session

Import-PSSession $session

Hopefully by now you will see how we are linking these together :-) we are calling the Import-PSSession cmdlet to our $session variable.

Once you hit return you will see it import the Exchange cmdlets from from Exchange.

We are now done and we have loaded the Exchange 2010 cmdlets.

I can now use them, for example below I have used the Get-Mailbox cmdlet against my test mailbox.

There are two things to note however:

1. If you have any issues with execution policies in Powershell ensure you have set Powershell to allow for remote signed scripts. To check, Get-ExecutionPolicy, to change to remote signed, Set-ExecutionPolicy remoteenabled

2. You must have Remote Powershell enabled for your user, by default this is only enabled for the account that installed Exchange, so to enable it perform the following on one of your Exchange 2010 servers

Set-User -identity youruserhere -RemotePowershellEnabled $true

Oliver Moazzezi

MVP - Exchange Server

No comments: