How to connect to Exchange Server via PowerShell
How to set up remote session to Exchange Server via PowerShell.
- Check the requirements for:
- Run Windows PowerShell.
Check your Execution policy settings:
If the execution policy is set to Restricted, change it to RemoteSigned or Unrestricted (this might need to be executed from PowerShell in the Run as administrator mode):
Provide the target server administrator credentials:
$LiveCred = Get-Credential
Configure the connection:
In the case of connecting to Exchange Server 2010, 2013, 2016:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://<target-server-address>/powershell/ -Credential $LiveCred
Be advised, the method above is not universal, i.e. depending on your target environment configuration you may be required to specify the authentication method as an argument (-Authentication Kerberos), connect via http instead of https etc. What is more, some options cannot be passed as New-PSSession arguments and must be specified as New-PSSessionOption and only then passed together as a variable, see example below.
$SessionOpt = New-PSSessionOption -SkipCACheck:$true -SkipCNCheck:$true -SkipRevocationCheck:$true
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri http://ex-mbx.domain1.example/powershell/ -Credential $LiveCred -SessionOption $SessionOpt -Authentication Kerberos
If you cannot use a hostname or FQDN as a target for PowerShell connection and must use an IP address instead see this article first.
In the case of connecting to Exchange Online (Office 365):
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection
Start the connection:
To disconnect, type:
Also, if you are logged in directly to the on-premises Exchange Server and for some reason cannot run the Exchange Management Shell, you can start Windows PowerShell and load the Exchange snap-in from there by executing the cmdlet below:
- Connect to Exchange Online using remote PowerShell in MS Technet