Quantcast
Channel: Practical 365
Viewing all articles
Browse latest Browse all 515

PowerShell Function to Connect to Exchange On-Premises

$
0
0

Connecting to Exchange on-premises using PowerShell remoting is a simple task, and means that you do not need to go the trouble of installing the Exchange management tools on your computer just to perform day to day administrative tasks.

There are three steps to establishing a remote PowerShell session to your Exchange server:

  • Capture admin credentials
  • Create a new PSSession
  • Import the PSSession

TechNet has the steps documented, but I prefer to use a PowerShell function in my profile to avoid typing out the steps manually.

Function Connect-Exchange {
    param(
        [Parameter( Mandatory=$false)]
        [string]$URL="ex2016srv1.exchangeserverpro.net"
    )

    $Credentials = Get-Credential -Message "Enter your Exchange admin credentials"
    $ExOPSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$URL/PowerShell/ -Authentication Kerberos -Credential $Credentials
    Import-PSSession $ExOPSession
}

In the example above I use a default URL value for quickly connecting to my preferred server, but can override it with the -URL parameter when I run the function.

After adding the function to your PowerShell profile and opening a new PowerShell console you simply run Connect-Exchange to establish a new remote PowerShell session to your Exchange server.

PS C:\> Connect-Exchange

As I mentioned earlier you can specify a different server with the -URL parameter.

PS C:\> Connect-Exchange -URL ex2016srv2.exchangeserverpro.net

This function is also available on Github.


This article PowerShell Function to Connect to Exchange On-Premises is © 2015 ExchangeServerPro.com

Get more Exchange Server tips at ExchangeServerPro.com

     

Viewing all articles
Browse latest Browse all 515

Trending Articles