Thursday, March 26, 2015

Running Exchange PowerShell session from a workstation

PowerShell, as the name suggests, is a powerful tool. In our previous posts, we have explained how to use it to modify Exchange transport agents, check email statistics on the server etc.

Normally you can simply run the Exchange console directly from the server. However, there is also a method to do it from a workstation.

This way you can avoid the whole process of running the remote desktop session and starting the console on the server. You just run the console on a workstation machine, skipping the whole RDP part.

First thing to do is to download and install Windows .Net Framework 4.5 and  Windows Management Framework.

Once it's all installed launch the PowerShell console on the workstation (make sure to start it with the "Run as Administrator" option) and enter the following:

Set-ExecutionPolicy RemoteSigned

The above command allows running scripts on the workstation.Agree to change this policy by entering "y" and hitting the Enter key:

Next command is:

$Login = Get-Credential

It allows to enter your Exchange administrative login credentials and save them as the $Login variable.

Next command is:

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://<Exchange Name>/PowerShell/ -Authentication Kerberos -Credential $Login

Make sure to replace the <Exchange Name> part of the command with the FQDN name of your Exchange server.

The last command is:

Import-PSSession $Session

which imports all necessary Exchange cmdlets.

You are now ready to use commands, such as Get-TransportAgent to administer your Exchange server remotely, directly from the PS console.