PowerShell ISE Exchange session

PowerShell ISeIn the previous post I have shown how to use PowerShell to remotely manage an Exchange server, while the approach is perfect for performing quick operations like creating a mailbox or running a couple of commands it can be come more difficult when you need to remember details for different customers and even more when you are developing a script and need something more flexible than the shell, in the post I will show how to add PowerShell exchange sessions to ISE.

PowerShell ISE Exchange – What is ISE?

ISE stands for Integrated Scripting Environment and as the name implies it is a host application for PowerShell which brings together the power of the shell with the ease of use of a development environment, among the features you can find ability to set break points, support for keyboard shortcuts (CTRL+C or CTRL+V anyone?) and much more.

One of the strongest PowerShell ISE points is the ability to customize it through the Windows PowerShell ISE Object Model which makes it really easy to add custom menus or, like in our example, Exchange sessions to remote servers.

ISE is usually the tool of choice when I am developing a complex scripts which requires more than a couple of lines of code, as you probably have experienced first hand developing scripts in a PowerShell session can be challenging.

PowerShell ISE Exchange – Add sessions

To be able to add PowerShell ISE Exchange sessions and load them automatically when starting PowerShell ISE we are going to add them to our PowerShell ISE profile which location is stored in the $profile variable which can be edited with notepad:

# Location of the PowerShell ISE Exchange profile

PS C:UsersLethe> $profile

PS C:UsersLethe> notepad $profile

Once opened the profile to add new sessions just input code similar to the following in the file:

"Connect to MBX-01", {
$user = Get-Credential
$ignoreCertificate = New-PSSessionOption -SkipRevocationCheck
$connectpoint = "http://srv-exch2k13-mb01.HeloCheck.com/PowerShell/"
$ExSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $connectpoint -credential $user -Authentication 'Kerberos'
Import-PSSession $ExSession

"Connect to MBX-02", {
$user = Get-Credential
$ignoreCertificate = New-PSSessionOption -SkipRevocationCheck
$connectpoint = "http://srv-exch2k13-mb02.HeloCheck.com/PowerShell/"
$ExSession= New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri $connectpoint -credential $user -Authentication 'Kerberos'
Import-PSSession $ExSession

Repeat the process for any additional Exchange session you need to define in PowerShell ISE, close the editor and restart it so that the $profile is sourced importing newly defined sessions as you can see in the bottom runtime pane of ISE:

Action                                          DisplayName                                     Shortcut                                       Submenus                                      
------                                          -----------                                     --------                                       --------                                      
...                                             Connect to MBX-01                               System.Windows.Input.KeyGesture                {}                                            
...                                             Connect to MBX-02                               System.Windows.Input.KeyGesture                {}

As you can see the newly defined connections are available under the Add-ons menu:

PowerShell ISE Exchange

clicking on one of the connections or pressing the associated key shortcut will cause PowerShell to execute associated code and connect to the remote Exchange server:

PowerShell ISE Exchange

Once the connect is completed you can verify it with the Get-PsSession and Exchange specific cmdlets, like Get-Mailbox, will be locally available to the ISE PowerShell session:

PowerShell ISE Exchange Session



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s