PowerShell is a command line shell that includes an environment for creating scripts. It is particularly designed for use by system administrators to manage, administer, monitor and troubleshoot. PowerShell uses some C# syntax. It is built on the .NET framework.
Commands issued in PowerShell are referred to as “cmdlets”.
As it is a Microsoft it can be used to leverage Office 365.
Ways to Leverage Office 365 with PowerShell
PowerShell is a tool most useful to sysadmins. So, most of the commands, cmdlets, used in Office 365 related to user and access management. The cmdlets we will discuss fall into the category. Here is a List of Powershell cmdlets to use with Office 365:
- Get-Command
- Get-MsolUser
- New-MsolUser
- Set-MsolUserPassoword
- Get-MsolGroup
- Add-MsolGroupMember
- Remove-MsoGroupMember
- Get-SPOSite
- New-SPOSite
- Get-mailbox
- Get-MailTrafficTopReport
Ensure you have connected your Office 365 instance to PowerShell. This includes installing the Office 365 module for PowerShell. If you need further instructions navigate here.
Office 365 PowerShell Commands for Automation
Get-Command
The Get-Command cmdlet shows the list of available Office 365 PowerShell commands
Get-MsolUser
The Get-MsolUser cmdlet will show all users with a valid license within your tenant. It will also display their DisplayName, City, Department and ObjectID parameters.
New-MsolUser
The New-MsolUser command is used to create a new user
There are additional variations of the MsolUser cmdlet.
The GetMsolAccountSku cmdlet displays the current number of account licenses.
This command can also be used with additional instructions to perform other tasks
Get-MsolAccountSKU | select -ExpandProperty ServiceStatus will list all available services
Set-MsolUserPassword
Get-MsolGroup
Add-MsolGroupMember
Remove-MsoGroupMember
Get-SPOSite
The Get-SPOSite command is used to remove a user from all of the sties they are connected to simultaneously.
New-SPOSite
Get-mailbox