Remote Exchange PowerShell Session in Powershell ISE

This post is also available in: Polish

 

During Microsoft Exchange servers administration we often use EMS (Exchange Management Shell). Many times it’s the best and the fastest way to achieve what we need. We can create Powershell scripts to automate some administrative actions.

Unfortunately lot of us to use Exchange Management Shell, first connect by RDP to Exchnage Server or workstation with Exchange Management Tools and then run EMS.

We can easly connect to Powershell Exchange Management Console from workstation using New-PSSession in Powershell ISE console.

Below we present how to add menu Powershell ISE to connect to Exchange Server Powershell Console.

First we need to run Powershell ISE console and write:

Set-ExecutionPolicy RemoteSigned

 

next we need to write to check powershell profile used on our computer:

$profile

 

 

Now we know where is located file with our powershell profile, but we have to check if this file exists.

To check if this profile file exists we have to run below command:

test-path $profile

 

If we receive True, it’s mean that file exists, but if we receive False we have to create this file.

To create profile file for Powershell console we have to run below command:

new-item -path $profile -itemtype file -force

 

Now we can again check if this file exists:

test-path $profile

 

With new created file we can start editing it to add menu to connect to our Exchange Server.
Run this command, to open file in Notepad:

notepad $profile

 

We have to add below code to file which we open in Notepad.

$psISE.CurrentPowerShellTab.AddOnsMenu.SubMenus.Add(
 "Connect to Exchange ExchangeServer1", {
 $user = Get-Credential
 $ExSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://serverexchange/PowerShell/ -Credential $user
 Import-PSSession $ExSession
 },
 "Control+Alt+1"
)

 

But in line with variable ExSession after ConnectionUri we have to specify Exchange Server to connect.
If we are connecting to Exchange Server with different credentials than we use on workstation with Powershell ISE, we have to use $user = Get-Credential. This will run windows where we have to write credentials to connect to Exchange.

But if we are using the same credentials on workstation as we need to connect to Exchange Server, we can modify this code and remove line with variable $user and change line with variable $ExSession like below:

$ExSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://exchangeserver/PowerShell/ -Authentication Kerberos

 

When we want to add few connections to menu we have to paste this code few times and remember to change Exchange Server address and shortcut “Control+Alt+1″ to “Control+Alt+2″ and etc.

 

When we finish configuration, save file, and restart Powershell ISE

When Powershell ISE will open, go to menu Add-ons and select Connect to server ExchangeServer1

 

From now to connect to Powershell console to ExchangeServer1 we don’t have to run RDP connection, just run Powershell ISE and select Connect to Exchange ExchangeServer1

Then after authentication we can use all Exchange Server CMDlets.

 

 

Print Friendly
Tagged , , , , , . Bookmark the permalink.

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>