What are all the Office 365 for Education PowerShell command options?
This was a question from a university in New Orleans looking to move to Office 365 for Education.
There are two PowerShell scenarios applicable to Office 365 for Education. The first scenario is leveraging PowerShell for overall management of your Office 365 tenant and the other PowerShell scenario is for leveraging PowerShell to manage Exchange Online. You can combine them into one PowerShell session or separate them into two different administrative streams if you have different Office 365 tenant administrators and Exchange Online tenant administrators. I broke them out into two distinct roles but you can certainly combine them into a single session.
What types of things can I do with Office 365 Remote PowerShell?:
Manage users
Manage group and role membership
Manage Office 365 domains
Manage Single Sign-on
Manage subscriptions and licenses
Manage company information and service
Manage Exchange Online
Setting up Office 365 Remote PowerShell to manage the tenant:
Step 1: On the administration workstation – the MS Online Services Sign-In Assistant is required as a prerequisite to leverage O365 PowerShell:
- Microsoft Online Services Sign-In Assistant 32-bit
- Microsoft Online Services Sign-In Assistant 64-bit
Step 2: Install the Office 365 Services module OR leverage PowerShell (if you don’t have Windows 7 or Windows Server 2008+)
- Microsoft Online Services Module for Windows PowerShell 32-bit
- Microsoft Online Services Module for Windows PowerShell 64-bit
OR
Leverage existing Windows 7/Windows Server 2008+ PowerShell or Grab Windows PowerShell here for older workstations.
I chose to leverage the stock PowerShell of all of my Office 365 for Education management but you could also use the Online Services module as well.
Step 3: Launch PowerShell – you can launch either one below – I launched ‘Windows PowerShell’
In either ‘Online Services PowerShell’ or ‘Windows PowerShell’ type in:
Import-Module msonline
$cloudcred = Get-Credential - Note: this can be any variable I just used ‘cloudcred’
Connect-Msolservice –cred $cloudcred
You are now connected to Office 365 via remote PowerShell.
If you want to see all your cmdlets available type:
Get-Command –Module msonline
The end output should look like this:
Step 4: optional – to manage Exchange Online in the same PowerShell session skip to Step 2 in the Exchange Online steps
Here I show how you can manage the Office 365 tenant and Exchange Online in a single session from either native PowerShell or Online Services Module:
or
How to connect to Exchange Online using PowerShell:
Step 1: You need to configure your workstation to support Remote PowerShell
Start Powershell or Start Online Service Module (from above) – I used native 64-bit version but you can use either (native with Win7 or Win Server 2008+) or grab it here.
You need to set a variable to equal Get-Credential. You can set it to any variable you want as long as you are consistent:
$CloudCred = Get-Credential
Type in your O365 Creds with powershell administrator permissions in the dialog – check your powershell permissions for O365 here.
Step 2: connect to Exchange Online by typing in:
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $CloudCred -Authentication Basic –AllowRedirection
to connect to the Exchange Online service remotely via PowerShell
Finally type in:
Import-PSSession $Session
to grab the Exchange Online specific cmdlets
This should be your screen when you are all done:
For more information visit here.
You can list all the available Exchange Online cmdlets with:
get-command |more
It will be a subset of cmdlets as not all on premises Exchange 2010 cmdlets are available to you for example. The good news is you can leverage some of your on prem Exchange 2010 scripts against Office 365.
Step 3: Disconnect when finished
Be sure to disconnect from the service when you are done as you are limited to 3 concurrent PowerShell sessions per tenant (15 min timeout after disconnect) by using:
Remove-PSSession $Session
Where can I find a list of all the Office 365 PowerShell cmdlets?
You can find a list of all your Office 365 cmdlets here.
What are the differences between Exchange 2010 on prem cmdlets vs. Exchange Online cmdlets?
You can find a list of all the Exchange Online cmdlets here.
Can I manage SharePoint Online or Lync Online with PowerShell?
As of today’s post, it is not possible to manage these with remote PowerShell.
Do I have to go through entering above every time I want to manage Office 365 via remote PowerShell?
No, you can write a PS1 script to automate the typing above. Here is a sample you can use:
Step 1:
Create your PS1 file in notepad or PowerShell ISE such as this (note: all the code is there even though it doesn’t appear that way just copy and paste below)
Import-Module msonline
$cloudcred = get-credential
Connect-msolservice -cred $cloudcred
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $CloudCred -Authentication Basic –AllowRedirection
Import-PSSession $Session
Step 2:
Save file with .PS1 extension in your c:\users\username folder – this is key to make it easy to execute in PowerShell
Step 3:
Open up PowerShell or Online Services Module and just type first two letters of PS1 file name and hit “Tab” key to autocomplete and then “Enter” to launch the script
Step 4:
Type in valid tenant administrator credentials
Should look something like this:
You are now connected to Office 365 via PS1 script file so you don’t have to remember all of this each time.