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.

About the Author

Paul Cunningham

Paul is a former Microsoft MVP for Office Apps and Services. He works as a consultant, writer, and trainer specializing in Office 365 and Exchange Server. Paul no longer writes for Practical365.com.

Comments

  1. Geetha Karuturi

    Hi Paul,
    Which $Credentials are you using On perm or Exchange ??

    1. Avatar photo
      Tony Redmond

      The post is about connecting to Exchange on-premises.

  2. Garrett

    Love your site Paul. Can you talk about using Import-PsSession vs. Export-PsSession when it comes to Exchange remoting? Could there be a performance advantage there?

  3. Javier

    Hi Paul

    the information help me to a lot but I have a question, It is possible to configure the VIP instead using the FQND of Exchange server?

    when I tried to configure the VIP I got error and error with the WinRM
    “[VIP.domain.com] Connecting to remote server failed with the following error message : WinRM cannot process the request. The following error occured while using Kerberos authentication: The network path was not found.”

      1. Javier

        I read the article from MS but it is possible to do it with Basic authentication? I opened a case with MS they said everything is fine and they asked me to use Basic instead Kerberos as that will be more work, they also suggested round robin DNS however that is not what I am looking for but I keep that as an option, i will give a try and enable the kerberos, thanks for the response,

        Have a great day

  4. Shane Wright

    Hey Paul,

    I added some features to your connect-exchange cmdlet including:

    Automatically find the powershell remoting server
    list all powershell remoting servers and choose one to connect
    list all powershell remoting servers by site or version and choose one to connect

    https://gallery.technet.microsoft.com/Connect-Exchange-740ed2b6

    Hope you like it!

    Shane

  5. MSMS MSMS

    How do you handle working with deserialized objects? e.g. Get-ExchangeServer | Get-MessageTrackingLog ?

    Best regards, MSMS MSMS

  6. Off2w0rk

    Hi Paul,

    thanks for the tip!
    I’m not a scripter, but can read and modify some. Currently we administer Exchange for several customers in our environment. How can we easily modify your script so it does the following:

    Press 1 to connect to server 1
    Press 2 to connect to server 2
    Press 3 to connect to server 3

    and so on?

    thanks and keep up the good work!

    1. Lasse Larsen

      You can use the Switch{} system for that.
      Create a menu with Write-host.

      Then
      $Choice = Read-host Please choose from list
      Switch{
      1{ Connect-exchange -URL xxxxxxxxx}
      2{ Connect-exchange -URL xxxxxxxxx}
      3{ Connect-exchange -URL xxxxxxxxx}
      }

      1. Lasse Larsen

        And I forgot to add Switch($Choice){ 🙂

  7. Barron

    Hi Paul,

    Thanks for the information, I have one question, how the session will end, according to technet with Remove-PSSession $Session ends the current sesion but that will not work with your script, if I close powershell the session will ends??

    thanks

  8. Jack P

    Good stuff!

    I use to create another version. It is a simple pass through without any prompt for read only stuff…

    Function Connect-Exchange2 {

    param(
    [Parameter( Mandatory=$false)]
    [string]$URL=”ex2016srv1.exchangeserverpro.net”
    )

    # it passes the cred of the current logon user
    $ExOPSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://$URL/PowerShell/ -Authentication Kerberos

    Import-PSSession $ExOPSession

    }

Leave a Reply