Connecting Exchange 2010 or 2013 Using Remote PowerShell

Xavier Mustin

Administrator
Staff member
#1
Connecting Exchange 2010 or 2013 Using Remote PowerShell

As noted above, TechNet only documents that PowerShell remoting should be used. Typically this means that we will use the following process to connect to an on-premises Exchange 2010 or 2013 server.

In the below examples we provide credentials and store them in the $UserCredentials variable. They are then presented as part of the configuration of the PowerShell $Session. Finally the PowerShell session is imported.

Sample code would look like the below examples.

Prompting For Authentication On Domain Joined Machine
Code:
$UserCredential = Get-Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUrihttp://<ServerFQDN>/PowerShell/ -Authentication Kerberos -Credential $UserCredential

Import-PSSession $Session
(Please note they are three separate lines which may wrap)



Using Logged On Credentials On Domain Joined Machine
An example of leveraging logged on credentials could look like this:

Code:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUrihttp://<ServerFQDN>/PowerShell/ -Authentication Kerberos
Import-PSSession $Session

With each of the above examples, the commands can be executed one line at a time, or saved into a PowerShell .PS1 script.


Disconnecting Using Remote PowerShell
Once we have completed our work, the PowerSession should be removed to clean it up.

Code:
Remove-PSSession $Session
 
Haut