There is tremendous value in Exchange Online using Windows PowerShell to manage Microsoft Exchange Online, Skype for Business, SharePoint Online and various other services with PowerShell.
[adrotate banner=”5″]
PowerShell (including Windows PowerShell and PowerShell Core) is a task automation and configuration management framework from Microsoft, consisting of a command-line shell and associated scripting language built on the .NET Framework used to Connect to Exchange Online using Windows PowerShell.
Exchange Online using Windows PowerShell
- On your local computer, open Windows PowerShell and run the following command.
- $UserCredential = Get-Credential
In the Windows PowerShell Credential Request dialog box, type your Office 365 user name and password, and then click OK.
- $UserCredential = Get-Credential
- Run the following command.
-
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
-
- Run the following command.
-
Import-PSSession $Session
-
Connect-MsolService -Credential $UserCredential.
- Be sure to disconnect the remote PowerShell session when you’re finished. If you close the Windows PowerShell window without disconnecting the session, you could use up all the remote PowerShell sessions available to you, and you’ll need to wait for the sessions to expire. To disconnect the remote PowerShell session, run the following command.
Remove-PSSession $Session
-
- How do you know this worked?
-
After Step 3, the Exchange Online cmdlets are imported into your local Windows PowerShell session and tracked by a progress bar. If you don’t receive any errors, you connected successfully. A quick test is to run an Exchange Online cmdlet, for example, Get-Mailbox, and see the results. (shows the Server your on and Quota)
If you receive errors, check the following requirements:
- A common problem is an incorrect password. Run the steps again and pay close attention to the user name and password you enter in Step 1.
- To help prevent denial-of-service (DoS) attacks, you’re limited to three open remote PowerShell connections to your Exchange Online organization.
- The account you use to connect to Exchange Online must be enabled for remote PowerShell. For more information, see Enable or disable access to Exchange Online PowerShell.
- TCP port 80 traffic needs to be open between your local computer and Office 365. It’s probably open, but it’s something to consider if your organization has a restrictive Internet access policy.
-
A few Sample Commands to Test with your Connection
Below are a few other commands you can try out once your connected to Microsoft Exchange Online (Connect to Exchange Online using Windows PowerShell).
- Get-MsolUser – Lists all users
- Remove-MsolUser -UserPrincipalName name@domain.com – Remove User/s