Read time: 6 minutes

Summary: Office 365 PowerShell commands make user account management and other tasks easier for admin. It helps users connect to Office 365 via PowerShell, manage users, passwords, licenses, groups, and sites. But before going to perform such tasks via PowerShell, don’t forget to protect your Office 365 from risks like mailbox removal and mass deletion.

If you’ve ever managed Microsoft at scale, you already know that the admin center looks simple until you have to do something repetitive. Imagine your manager asked you to create 1 user in Office 365. It could be easy. If you’re asked to add 50 users with licenses, policies, and mailbox setup, the situation may change for you. And that is exactly where Office 365 PowerShell commands enter, not as a luxury but as a necessity.

With O365 PowerShell commands, admins can create users and assign a license, reset passwords, manage mailboxes, and even export Office 365 mailboxes, automatically, along with bulk operations & advanced control.

Why Office 365 PowerShell Commands Matter

Microsoft 365 is no longer just an email platform; it is where companies run their daily business operations, store important data, & collaborate in real-time. As its usage has grown, admins are no longer managing 10-20 users; they are handling a massive number of users. PowerShell helps to make the process, like access control, user activity monitoring, etc., automated.

All in all, Office 365 PowerShell cmdlets are important for managing users at scale, but they can be tedious for tasks like data export and compliance purposes. So, every Office 365 admin should at least have a few important PowerShell commands in their tasks, effectively in no time.

Benefits of Office 365 PowerShell Commands

O365 PowerShell commands may look laborious at first, but they are quite performing and give qualitative outcomes. Some important advantages of using PowerShell cmdlets for 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.
  • Easier than the Office 365 admin center (GUI-based).

Important to Know: The Azure Active Directory (AzureAD) PowerShell module is being deprecated and replaced by the Microsoft Graph PowerShell SDK. Now use the Microsoft Graph PowerShell SDK to access all Microsoft Graph APIs.

How Office 365 PowerShell Commands Actually Do Well

Here are the set of important PowerShell commands needed to perform tasks like management of Office 365 Users, management of Office 365 passwords and account settings, etc. If you need to perform such a task, use the Office 365 PowerShell commands given. But first, connect to Office 365.

Initiate the Microsoft Graph PowerShell SDK that you’ve installed. Then, execute the following commands to establish a connection with your Office 365 account.

Connect-MgGraph -Scopes “User.Read.All”,”Group.ReadWrite.All”

At this point, you’ll be prompted to input your Office 365 account credentials. Please provide them to establish the connection to Office 365.

Following this connection, you gain the ability to oversee various Office 365 functions related to users, groups, sites, passwords, and more. Now, let’s explore a few actions that can be accomplished using Office 365 PowerShell cmdlets.

Task 1: Office 365 PowerShell Commands for Management of Office 365 Users

The following Office 365 PowerShell cmdlets that admins can use to manage their Office 365 users:

  • To get the complete list of all user mailboxes in your Office 365 account, run this command:
    Get-MgUser | Select DisplayName, City, Department
  • Create a new user by running this command:
    New-MgUser -UserPrincipalName username@sharepointarena.onmicrosoft.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-MgUser -UserPrincipalName “<email address>” -DisplayName “<display name>”
    Restore-MgUser -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.

Task 2: O365 PowerShell commands for Management of Office 365 Password and Account Settings

Another crucial task achievable through PowerShell in Office 365 involves the automated password setting and account management.

  • To set the Office 365 account password, try this command in PowerShell:
    Set-MgUserPassword-UserPrincipalName “<email address>” -NewPassword “New Password”
  • To set or update the Office 365 account user principal name, use this cmdlet:
    Set-MgUser-UserPrincipalName “<email address>” -NewUserPrincipalName “New User Principal Name”

Task 3: Important PowerShell commands for 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:

  • Run the below command in PowerShell to view all the licensed users in Office 365:
    Get-MgUser | ft UserPrincipalName, DisplayName, *lic*
  • To assign a license to a specific Office 365 user, run this cmdlet:
    Set-MgUserLicense -UserPrincipalName “user name” -AddLicenses “<licensed name>”

Task 4: Important PowerShell Commands to Manage Office 365 Groups and Sites

  • You can add a member to an Office 365 group using PowerShell. The commands are given as under:

    Add-MgGroupMember -GroupObjectId <groupobjectid> -GroupMemberObjectId – <groupmemberobjectid> -GroupMembertype User
  • To get all the commands available in Office 365, type this cmdlet:

    Get-Command mg

Office 365 PowerShell Commands are a Double-Edged Sword

Along with the various benefits and admin-level assistance, O365 PowerShell commands also lead to mass deletion, mailbox removal, malicious subscription, and other issues. So, it is necessary to back up Office 365 data regularly to keep Office data safe. However, you can also use PowerShell commands to export a mailbox to PST Office 365, but you already know how commands are performed and how they impact.

To counter such issues, a professional solution like Kernel Export Office 365 to PST can be the only way out. It requires no complex steps or PowerShell commands. It easily exports Office 365 data to a PST file along with other file formats like MSG, DOC, HTML, MHT, PDF, EML, etc. With this tool, the Office 365 export process is so simple that even novices and professionals can perform it as well with no assistance needed.

Keep Your Data Safe Before Running Office 365 PowerShell Commands

We hope you are now familiar with the Office 365 PowerShell commands for different tasks like managing Office 365 users, including their passwords, account settings, licenses, and more. These cmdlets simplify the GUI-based hassle for bulk management of Office 365 groups and boost the effectiveness of administrators in maintaining the environment.

An Office 365 backup helps to prevent data from serious issues. So, consider using the recommended tool to backup data more rapidly and effortlessly. So, don’t put your business in loss while performing Office 365 PowerShell commands, backup the data first.

Common Queries About Office 365 PowerShell Commands

Q: What is PowerShell in Microsoft 365?

A: PowerShell is a command-line tool that helps admins to automate tasks like user management, license assignment, mailbox configuration, etc.

Q: What permissions are required to run PowerShell commands?

A: You need admin roles such as global admin or user admin, depending on the task you’re going to perform.

Q: Is PowerShell enough for managing Office 365?

A: Yes, PowerShell commands are enough for managing Office 365, but are suitable for admins only.

Q: Is there any PowerShell command to export a mailbox to PST in Office 365?

A: No, there is no direct PowerShell command that can export Office 365 to PST. Instead of PowerShell, you can use a professional tool for easier and more effective Office 365 export to PST.

Kernel Export Office 365 to PST
Related Posts