This article is tagged under “PowerShell Nuggets”, meaning the style is KIS (Keep It Simple!) In case that you want to read more detailed explanation, use the following link: Using Remote PowerShell to manage Office 365 | Part 3/3
Step 1 – Run the PowerShell console using administrative rights (Run as Administrator).
To change the PowerShell Execution Policy, we need to run the Windows PowerShell by using the option: Run as administrator
Right click on the PowerShell Console icon and choose the option: Run as administrator.
Update the default PowerShell Execution Policy
By default, the PowerShell console will not allow us to run a script.
We can enable script execution by changing the default PowerShell Execution Policy to Unrestricted. (The default mode is: Restricted).
To change the Execution policy open the PowerShell console and type the command:
Step 2 – Creating remote session to Exchange Online
For creating the remote connection, we will need to use a set of three PowerShell commands. Each command performs a different task and includes variable that serves as a “container” for information such as user credentials, URL etc.
Copy the following “Block” of PowerShell commands and paste it on the PowerShell console:
PowerShell command Example
$UserCredential = Get-Credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
A pop out windows will appear. Type your credentials by using the UPN (user Principal name) format. For example [email protected]
After executing the command, the following message appears:
“WARNING: Your connection has been redirected to the following URI: “https://pod51013psh.outlook.com/PowerShell-LiveID?PSVersion=2.0 ” WARNING: Your connection has been redirected to the following URI: https://dbxprd0312psh.outlook.com/PowerShell-LiveID?PSVersion=2.0 ”
On the last screen, we can see the process of the import Exchange Online cmdlets
Congratulations! You are now connected to the Exchange Online.
Step 3: Verifying the remote PowerShell connection
Q: How can we know if the remote session was successfully created?
A: To verify that we are connected, we type the name of Exchange Online cmdlets such as –
This command will display a list all the mailboxes that were created.
In the screenshot, you can see the list of Exchange Online mailboxes.
We really want to know what you think about the article