Monitor Work from Home Employees with Employee Desktop Live Viewer.

Read More

Some Important PowerShell Commands to Manage Office 365 Accounts

Megha Sharma
Megha Sharma Updated On - 09 Mar 2021

This article is about the PowerShell cmdlets that can be used in Office 365 to manage user accounts and perform many other actions.

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 to 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. Though you can manage many tasks using Office 365 admin center, PowerShell is considered as a more professional and comprehensive way to manage Office 365 tasks. Let us see a few actions that can be managed with Office 365 PowerShell.

Task1 – Management of Office 365 Users

  1. To get the complete list of all user mailboxes in your Office 365 account, run this command:
    Get-MsolUser | Select DisplayName, City, Department
  2. Create a new user by running this command:
    New-MsolUser -UserPrincipalName username@sharepointarena.onmicrosoft.com -DisplayName “User name” -FirstName “User first name” -LastName “User last name”
  3. 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 the deletion (the default retention period). After this period, the mailbox gets deleted 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.

  1. To set the Office 365 account password, try this command in PowerShell.
    Set-MsolUserPassword-UserPrincipalName “<email address>” -NewPassword “New Password”
  2. To set or update the Office 365 account user principal name, use 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 using PowerShell cmdlets.

  1. Run the below command in PowerShell to view all the licensed users in Office 365.
    Get-MsolUser | ft UserPrincipalName, DisplayName, *lic*
  2. To assign a 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 add a member to an Office 365 group using PowerShell. The commands are given as under:

Add-MsolGroupMember -GroupObjectId <groupobjectid> -GroupMemberObjectId – <groupmemberobjectid> -GroupMembertype User

To get all the commands available in Office 365, type this cmdlet:

Get-Command *msol*
Benefits of PowerShell cmdlets in Office 365

Some important advantages of using PowerShell cmdlets in Office 365 are:

  • Automates almost all Office 365 functions
  • Reduces the efforts of Office 365 administrators
  • Makes the execution of tasks more reliable and accurate
  • Offers to use services across different deployments
  • It is more comprehensive than Office 365 admin center

Hope this article is helpful to know the importance of PowerShell in Office 365.

Conclusion

PowerShell cmdlets helps them manage Office 365 users, their passwrds/account settings, license, etc. Also, it helps them manage Office 365 groups. PowerShell cmdlets make it easy for Office 365 administrators to manage the environment more effectively.