Within this article we will be going over the steps you need to take to connect PowerShell to Office 365. Before we begin, you will need to meet the following requirements.
- Operating System:
- Windows 7
- Windows 8
- Windows 8.1
- .NetFramework 4 and higher
- Microsoft Online Service Sign-in Assistant (http://go.microsoft.com/fwlink/?LinkId=286152)
- Global Administrator Rights in your Office 365 Tenant.
- Windows Azure Active Directory Module for Windows PowerShell.(http://technet.microsoft.com/en-us/library/jj151815.aspx)
Once you meet all of the requirements, go ahead and start up Windows Azure Active Directory Module for Windows PowerShell. You will need to run it as an Administrator. Once Windows Azure AD Module for Windows PowerShell starts up you will want to change the Execution Policy.
- Set-ExecutionPolicy –ExecutionPolicy Unrestricted
You will be asked if you want to change the Execution Policy, press Enter or Y to continue.
Next, you will want to open notepad and write a script that will allow you to connect to Office 365, without having to type out each command every time you want to connect PowerShell to Office 365.
|1||$LiveCred = Get-Credential|
|2||$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection|
|5||Connect-Msolservice –Credential $LiveCred|
Each section represents a line of text, you will need to write them/copy them in this order into your NotePad. After you have entered all 5 lines of text into your NotePad, you will want to save your file as a .ps1 file.
After you have saved your file, open Windows Azure AD Module for Windows PowerShell and navigate to your file.
You need to specify your File and its Pathname, once you have located your file, press Enter. You should be asked to enter your Username and Password. Enter your Office 365 Username (this User needs to be a Global Administrator in your Office 365 Tenant).
Once the script finishes running, you will be connect to Office 365. You will now to able to manage your Office 365 Tenant from PowerShell.
To learn more about PowerShell cmdlets, please visit: http://technet.microsoft.com/en-us/library/jj151815.aspx