To setup a remote PowerShell session, two PowerShell commands must be run
If you are running PowerShell on the same machine as the Exchange installation then you do not need to setup a remote PowerShell session. You should be able to run the Exchange cmdlets directly in the Exchange Management Shell on the server.
Step-by-step guide
- Open PowerShell on your workstation.
- Run the following command.
$sesh = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell -credential (New-Object -TypeName System.Management.Automation.PSCredential -argumentlist 'ADMIN_EMAIL',(ConvertTo-SecureString 'ADMIN_PASSWORD' -AsPlainText -Force)) -Authentication Basic -AllowRedirection
You should replace ADMIN_EMAIL and ADMIN_PASSWORD with the settings for your system. The PowerShell URL of https://ps.outlook.com/powershell is the PowerShell URL for Office 365. If you are connecting to a PowerShell session on an Exchange 2010 system, you should change this URL to the PowerShell endpoint for your system.
- When the PowerShell session has been started, run the following command to import the Exchange cmdlets into the current session.
$imp = Import-PSSession -Session $sesh
When the PowerShell session has been setup correctly, you can run Exchange cmdlets from your PowerShell session.
Common Issues
WinRM errors – When connecting to an Exchange 2010, the most common errors that can be seen are related to the WinRM framework. Carefully examine any errors returned and check the Microsoft KB articles for resolutions.
Execution policy – If errors are obtained when running Import-PSSession, you may need to set the local script execution policy by running Set-ExecutionPolicy RemoteSigned
.
Connecting via a proxy – If you connect via a proxy to the Internet you may need to setup proxy access using session options on the command. There are various ways this can be done but if you can use the same proxy as the default system proxy run the following command before running New-PSSession
:
$ProxyOptions = New-PSSessionOption –ProxyAccessType IEConfig
You should then append the following to the New-PSSession
command:
-SessionOption $ProxyOptions
Session options – If you need to perform authentication to the proxy or you need to connect to a proxy other than the default system proxy, please see the Microsoft help topic about New-PSSessionOption
here. If you need to use extra session options then you will also need to modify the PowerShell scripts that the tool runs as part of the migration process.