This article is about the PowerShell cmdlets that can be run in Office 365 to manage user accounts and perform many other actions.
PowerShell in Office 365
Office 365 users can run PowerShell cmdlets by downloading the Microsoft Online Service Sign-in Assistant for IT Professionals RTW and installing it on your system (64-bit version recommended). Now that this service is successfully installed on your system, you need to download and install Windows Azure Active Directory Module for PowerShell on your system.
Connect Office 365
Launch the installed Windows Azure Active Directory Module for PowerShell and then run these commands to connect your Office 365 account.
$officecredentials = get-credential
connect-msolservice -credential $officecredentials
Now, you will be asked to enter the Office 365 account credentials. Enter them to finally connect to Office 365.
After this connection, you can manage many Office 365 functions related to users, groups, sites, passwords, etc. Let us see how.
Task1 – Management of Office 365 Users
- To get the complete list of all user mailboxes in your Office 365 account, run this command:
Get-MsolUser | Select DisplayName, City, Department
- Create a new user by running this command:
New-MsolUser -UserPrincipalName email@example.com -DisplayName “User name” -FirstName “User first name” -LastName “User last name”
- To remove or restore any user mailbox of Office 365, try these cmdlets:
Remove-MsolUser -UserPrincipalName “<email address>” -DisplayName “<display name>”
Restore-MsolUser -UserPrincipalName “<email address>” -DisplayName “<display name>”
Note: It restores the user mailbox up to 30 days after deletion (default retention period). After this period, the mailbox gets delete permanently.
For more information, get standard details on Office 365 PowerShell.
Task2 – Management of Office 365 Password and Account Settings
Another important task that you can carry out in PowerShell with Office 365 is the automatic setting of passwords and managing the account settings.
- To set the Office 365 account password, try this command in PowerShell.
Set-MsolUserPassword-UserPrincipalName “<email address>” -NewPassword “New Password”
- To set or update the Office 365 account user principal name using this cmdlet.
Set-MsolUser-UserPrincipalName “<email address>” -NewUserPrincipalName “New User Principal Name”
Task3 – Management of Office 365 Licenses
You can view the licensed users, assign a license and manage the licenses of a specific user in Office 365.
- Run the below command in PowerShell to view all the licensed users in Office 365.
Get-MsolUser | ft UserPrincipalName, DisplayName, *lic*
- To assign license to a specific Office 365 user, run this cmdlet:
Set-MsolUserLicense -UserPrincipalName “user name” -AddLicenses “<licensed name>”
Task4 – Management of Office 365 Groups and Sites
You can manage Office 365 groups by adding member to group. The commands are given as under:
Add-MsolGroupMember -GroupObjectId <groupobjectid> -GroupMemberObjectId – <groupmemberobjectid> -GroupMembertype User
To get all the commands available in Office 365 management, type this cmdlet:
Benefits of PowerShell cmdlets in Office 365
Some important advantages of using PowerShell cmdlets in Office 365 are: to fulfill many functions are:
- Automates almost all Office 365 functions
- Reduces the efforts of Office 365 administrators
- Makes services more reliable
- Offers to scale across different deployments
Hope this article is helpful to know the importance of PowerShell in Office 365.