How to Connect PowerShell to Office 365
In order for you to manage your Office 365 account, you will need to download and install a few tools. You can manage your account from any Windows PC, you don’t need to install them to a server so can manage accounts directly from your PC or laptop.
Download and install each of the following tools:
Microsoft Online Services Sign-in Assistant
Azure Active Directory Module
SharePoint Online Module
Skype for Business Online Module
Once everything is installed open up Windows PowerShell from the start menu and run it as administrator.
The PowerShell window opens up and we’re in business!
Connecting to Office 365
When you start out you only need three commands to connect to the 365 portal. The first will prompt you for the login details of a global administrator and save them into the $credential variable, the second will import the basic 365 PowerShell commands and the third will connect you up using the saved login credentials.
$credential = Get-Credential
Connect-MsolService -Credential $credential
Next you will need to update the PowerShell Execution policy so that some of the commands will run correctly. The following commands will allow you to run remote signed scripts.
Set-ExecutionPolicy “RemoteSigned” -Scope Process -Confirm:$false
Set-ExecutionPolicy “RemoteSigned” -Scope CurrentUser -Confirm:$false
If you want to manage Skype for Business Online, you will need to import the Lync Online module and import the session.
$session = New-CsOnlineSession -Credential $credential
If you want to manage SharePoint you will need to run the following:
Connect-SPOService -url https://office365laba-admin.sharepoint.com -Credential $credential
And finally if you want to manage Exchange online you will need to run the following to create and import an Exchange session.
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri “https://outlook.office365.com/powershell-liveid/” -Credential $credential -Authentication “Basic” –AllowRedirection
Once you have all of the modules loaded you can list all of the available commands by running: Get-Command it’s a good idea to browse over the available commands and familiarize yourself with them. There have been plenty of times where I’ve seen a command that looks interesting and then I go on to use it in a script.
Connecting PowerShell to Office 365 is relatively straight forward and opens up lots of new opportunities. If you work with Office 365 as part of your job then learning to use PowerShell is a great way to get ahead of your peers and make your life easier. Follow the blog to get lots of helpful tips on managing Office 365 using PowerShell, its what I do every day so there should be something for everyone.[email-download download_id=”9801″ contact_form_id=”9351″]
If you want to get stuck in then you can buy my book from Amazon either the paper back or kindle version. My advice is to buy the paperback version so you can keep it on your desk for easy reference!