Updated 4 months ago

Manage Microsoft 365 Licenses using MS Graph PowerShell

by Kathy Cooper

7 min read

No Comments

Due to Msol and Azure AD PowerShell module deprecation, administrators should switch to MSGraph PowerShell to manage Office 365 users, groups, and licenses. So, we have upgraded our earlier Office 365 license management script to adopt MS Graph cmdlets.

With this All-in-One PowerShell script, admins can perform license assignments, license removals, bulk license management, license reporting, etc. Let’s dive into the script and its functionality.

Script Download: ManageM365Licenses

Script Highlights:

  • The script uses MS Graph PowerShell module.
  • Generates 5 Office 365 license reports.
  • Allows you to perform 6 license management actions that include adding or removing licenses in bulk.
  • License Name is shown with its friendly name like ‘Office 365 Enterprise E3’ rather than ‘ENTERPRISEPACK’.
  • Automatically installs MS Graph PowerShell module (if not installed already) upon your confirmation.
  • The script can be executed with an MFA enabled account too.
  • Exports the report result to CSV.
  • Exports license assignment and removal log file.

Manage Microsoft 365 Licenses using MS Graph PowerShell:

This script helps admins to manage Microsoft 365 licenses efficiently and effectively. It supports the following actions.

Microsoft 365 License reporting and management using MS Graph

Microsoft 365 License Reports

  • Get all licensed users report
  • List all unlicensed users report
  • List users with a specific license type
  • Get all disabled users with licenses
  • Get Microsoft 365 subscription usage report

Microsoft 365 License Management

  • Bulk license assignment to Microsoft 365 users (CSV input)
  • Assign multiple licenses to bulk users (CSV input)
  • Remove all licenses from a user
  • Remove all licenses from bulk users (CSV input)
  • Remove a specific license from all users (i.e., license cleanup)
  • Remove all licenses from disabled users (i.e., license optimization)

Note: License removal functionality is tailored for direct license assignments and does not support inherited licenses. If there are overlapping direct and group-based licenses, remove the direct licenses to avoid duplication.

Also, you can check if a user license is directly assigned or inherited before proceeding.

Manage Microsoft 365 Licenses – Script Execution Methods:

To run this script, you can choose any of the methods given below.

Method 1: Execute the script with MFA and non-MFA account.

Method 2: Execute the script by explicitly mentioning the required ‘Action’.

Method 3: To perform multiple actions without executing the script several times, you can use ‘MultipleActionsMode’ param.

It will show the main menu until you terminate the script by providing input as 0.

Detailed Script Execution Methods:

Our script supports the following parameters which helps to pass the values as parameters.

  1. LicenseNames – To get a list of users with a specific license type.
  2. UsageLocation – To set usage location for Microsoft 365 users.
  3. Action – To directly specify action number instead of selecting it from main menu.

Microsoft 365 License Reports:

With this script, admins can generate 5 different Microsoft 365 license reports.

Microsoft 365 Licensed Users Report:

To get all licensed users in the Microsoft 365 environment, run the script as follows or select the required action from the main menu.

Sample Output:

Get all licensed users PowerShell

To get a more detailed report, you can check our dedicated blog on the Microsoft 365 users’ license assignment report.

Microsoft 365 Unlicensed Users Report:

To find users without licenses, execute the script with Action or choose the needed action from the menu.

Sample Output:

Office 365 get unlicensed users report

This report helps to identify unlicensed users and assign the required licenses based on their need.

Get Users with a Specific License Type:

Often admins want to get a list of users with a specific subscription or license. In such a situation, this report will come in handy. To find users with a specific Office 365 license, execute the script by simply passing the license name. For example,

It will list all the users with E3 license. If you are not sure about the license SKU name, you can generate the license usage report using Action 5.

Sample Output:

List users with E3 license in Office 365

Get All Disabled Users with Licenses:

To optimize license usage, it’s necessary to identify the cost spent on unused licenses. In such case, finding inactive users and identifying disabled users with licenses will help you. To get licensed users in the disabled state, run the script as shown below.

Sample Output:

Find disabled users still licensed in Office 365

Generate Microsoft 365 License Usage Report:

With this report, admins can find the active license units and consumed license units. Based on the available license units, admins can plan the license purchase or license cleanup. To generate license usage report, you can follow the below format.

Sample Output:

Office 365 license usage report

Microsoft 365 License Management:

Assigning licenses to M365 users can be challenging for administrators, especially in large organizations. Licenses can be given directly to users or shared through groups. But just giving licenses isn’t enough. it’s also important to track group-based licensing and direct assignments to make sure only the right people have access.

This script streamlines the process, making it easy for admins to assign and remove licenses in bulk. The script will ask for input CSV file location and the license name to be assigned or removed. At the end, the log file will be generated to know the license assignment or removal status.

Assigning Licenses to Microsoft 365 Users using PowerShell:

Assign a License to Bulk Users through Input CSV:

To assign a license to a list of Microsoft 365 users, you can run the script as follows.

Execution Method:

Assign-Office-365-license-in-bulk

Sample Input CSV file:

Assign or remove license in bulk

Sample Output Log file:

Office 365 license assignment log file

Additionally you can also make use of Microsoft365DSC tool to assign licenses for bulk users.

Assign Multiple Licenses to Microsoft 365 Users (Import CSV):

To assign multiple licenses to bulk users, run the script as follows.

It will ask for input file location and licenses to be assigned. You can give multiple license names as a comma separated value. You can refer to the screenshot below for the input format.

Assign Usage Location for Microsoft 365 Users:

Microsoft 365 users must have a usage location to assign licenses. Without usage location, you will get an error ‘License cannot be assigned to a user without a usage location specified’. To avoid this error during license assignment, our script helps you set usage location for Microsoft 365 users.

While running the license assignment use cases, you can set usage location to Office 365 users whose usage location value is empty. For example,

Or

The first example sets usage location as US for the users in the CSV file (whose usage location is empty) and then assigns multiple licenses to users (i.e., Action 7). Later, helps to select the required action from the main menu and then assigns the license usage location.

Unassign Licenses from Microsoft 365 Users using PowerShell:

Remove All Licenses from a User:

To remove all licenses from a user, run the script as follows.

It will ask for the user’s UPN. After providing the user identity, the script will remove all the licenses from a user.

Remove All Licenses from Bulk Users (Input CSV):

When you want to cleanup licenses from inactive users or former employees, this would be helpful. With this method, you can remove all the assigned licenses from a list of users.

After executing the above format, the script will ask for input CSV file location. After entering the path, it will remove licenses from the users in the input file.

Remove a Specific License from All the Users:

Due to license usage or cost, admins might switch to another license or subscription. In that case, you can use this method. It will remove a specific license from all the users in the organization.

It will ask for a license to be removed. After entering the license plan, the script will remove that specific license from all users.

Unassign Licenses from Disabled Users:

This is one of the license optimization techniques. To remove licenses from disabled users, run the script as follows.

You can refer to the log file to know a list of disabled users and their licenses.

Get More Detailed Office 365 License Report:

If you want to get more detailed Office 365 license reports based on

  • Regainable licenses
  • Users and Licenses
    • Licensed users
    • Unlicensed users
    • Users with specific subscription
    • Users with free subscription
    • Users with trial subscription
    • User license changes
  • License expiry
    • Purchased subscription expiring users
    • Purchased subscription expired users
    • Trial expiring users
    • Trial expired users
    • Users with suspended subscription
  • Subscription
    • Subscription usage report
    • Expired subscription
    • Unused subscription
    • Purchased subscription
    • Trial subscription

you can take a look at AdminDroid Microsoft 365 reporting and auditing tool.

AdminDroid provides over 100+ reports and a handful of dashboards completely for free. It includes reports on Users, Licenses, Groups, Group Members, Devices, Login Activities, Password Changes, License Changes, and more. The free edition doesn’t have any restrictions in reporting functionalities such as customization, scheduling, and exporting. For your Azure AD reporting and auditing needs, you can download Free Office 365 reporting tool by AdminDroid and see how it helps for you.

Office 365 license dashboard

Each report provides AI-powered graphical analysis to gain insights and understand the data in a visually appealing manner.

manage Microsoft 365 licenses

Additionally, AdminDroid Microsoft 365 reporting tool provides 1500+ pre-built reports and 20 smart visually appealing dashboards to know about your Office 365 environment at a glance. It generates reports on Office 365 reporting, auditing, analytics, usage statistics, security & compliance, etc. on multiple Microsoft 365 services.

I hope we have covered most of the use cases to manage Microsoft 365 licenses effectively. If you need some more granular use cases like assigning Microsoft 365 licenses based on users’ roles or departments, you can make use of Microsoft365DSC. Microsoft also introduces the Entra License utilization portal to view Entra license usage and manage it efficiently. If you have any other requirements, you can reach us through the comment section.

Share article