The content below is taken from the original ( Office 365 License Reporting and Management using PowerShell), to continue reading please visit the site. Remember to respect the Author & Copyright.
Microsoft 365 administrators need to manage users and their licenses efficiently to reduce license costs. Also, it is necessary to understand users’ requirements before assigning the license and identify unused licenses to optimize license management.
If you are a small organization, you can use Microsoft 365 admin center to assign and monitor licenses. But admin center is not feasible for large organizations. In this case, you can use PowerShell cmdlets to manage licenses. But, if you are new to PowerShell, it will be challenging to assign or remove licenses in bulk and generate license reports.
To overcome the difficulties, we have created an All-in-One PowerShell script for M365 license management. Yes! A single script can perform more than 10 Office 365 license management and reporting activities.
Script Download: O365LicenseReportingAndManagement.ps1
- Generates 5Office 365 license reports.
- Allows to perform 6 license management actions that includes, adding or removing licenses in bulk.
- License Name is shown with its friendly name like ‘Office 365 Enterprise E3’ rather than ‘ENTERPRISEPACK’.
- The script can be executed with an MFA enabled accounttoo.
- Exports the report result to CSV.
- Exports license assignment and removal log file.
- The script is scheduler-friendly. i.e., you can pass the credentials as a parameter instead of saving them inside the script.
Office 365 License Reporting and Management using PowerShell Script:
As earlier said, you can use this script to generate various license reports and to perform license management actions. We have listed a few significant actions here.
Office 365 License Reporting
- Get all licensed users report
- Get all unlicensed users report
- Get users with a specific license type
- Find all disabled users with licenses
- Office 365 license usage report
Office 365 License Management
- Bulk: Assign a license to users (input CSV)
- Bulk: Assign multiple licenses to users (input CSV)
- Remove license from a user
- Bulk: Remove all licenses from users (input CSV)
- Remove specific license from all users
- Remove all licenses from disabled users
Office 365 License Reporting and Management Tool – Execution Methods:
To run this script, you can choose any one of the below methods.
Method 1: Execute the script with MFA and non-MFA account
Method 2: Execute the script by explicitly mentioning credential and the required ‘Action’.
.\O365LicenseReportingAndManagement.ps1 -UserName [email protected] -Password XXX –Action 1
You can use the above format to automate the report generation. If the admin account has MFA, you need to disable MFA based on the Conditional Access policy to make it work.
Method 3: To perform multiple actions without executing the script several times, you can use –MultipleActionsModeparam.
It will show the main menu until you terminate the script by providing input as 0.
Unlock the Full Potential of this Script
The script supports the following in-built params to ease your Office 365 license management and reporting needs.
1.Action – To directly specify a reporting or management action instead of selecting it from main menu.
2.LicenseName – To get users with specific License Plan.
3.UserName and Password – To schedules the PowerShell script without interactive login.
4.MultipleActionsMode– To show main menu again after completing an action. It will help you to perform multiple actions continuously without executing the script again and again.
Export all Licensed Users in Office 365:
To get a list of licensed users in your organization, run the script as follows or select the required action from the main menu.
.\O365LicenseReportingAndManagement.ps1 -Action 1
Using this report, you can find licensed users and their assigned licenses, license friendly names, account status, etc.
Note: You can refer our earlier blog to get detailed license reportalong with the assigned services and their status.
Get Unlicensed Users in Office 365 using PowerShell:
To view all the unlicensed users in your organization, run the below code directly or choose the required option from the menu.
.\O365LicenseReportingAndManagement.ps1 -Action 2
By referring to this report, admins can identify users who don’t have any license plan and assign them a license, if required.
Export List of Users with a Specific License Type:
To get Office 365 users with a specific license plan, run the script as follows.
.\O365LicenseReportingAndManagement.ps1 -Action 3
It will ask for a license plan. After entering the license plan, the script will list the licensed users matching that license.
For example, to get a list of users with the E3 license, enter “Contoso:EnterprisePack” when the script prompts for the license name.
You can also pass the License Plan as a parameter as shown below.
.\O365LicenseReportingAndManagement.ps1 -Action 3 –LicenseName Contoso:EnterprisePack
The sample output lists all the users with E3 license.
Get Disabled Users Still Licensed in Office 365:
Generally, former employees’ accounts are disabled after they leave the office. In some situations, you may want to recover the Office 365 license from the departed users so that you can assign them to some other users. To find licensed disabled users, run the script as follows.
.\O365LicenseReportingAndManagement.ps1 -Action 4
The exported report contains UPN, Display Name, License Plan, License Plan Friendly Name, Department, and Job Title.
Office 365 License Usage Report:
Office 365 license usage report lists all the subscriptions available in your organization, along with the active license count and assigned license count. Bu referring to this report, you can calculate the unassigned license count.
To generate a license usage report, execute the script and select the needed action from the menu. Else, directly run the below code.
.\O365LicenseReportingAndManagement.ps1 -Action 5
Bulk Assign Office 365 License using PowerShell:
Users must have Office 365 license to use any Microsoft 365 services. Admins can assign the license(s) in bulk by using our PowerShell script. We have covered the most requested use cases below.
Assign a License to Users from CSV:
To assign Office 365 license to multiple users using a CSV file, run the PowerShell script as follows.
.\O365LicenseReportingAndManagement.ps1 -Action 6
The script will ask for the CSV file path. We have given an example for the input details below.
Input File Format:
The input CSV/txt file must follow the format below: UPN of users separated by new line without a header.
Output Log File- Sample
After the script execution, you can refer to the ‘Office365_License_Assignment_Log’ file to know about the license assignment result.
Assign Multiple License to List of Users:
To assign multiple licenses to Microsoft 365 users, execute the script as shown below.
.\O365LicenseReportingAndManagement.ps1 -Action 7
It will ask for the CSV file location and the licenses to be assigned. You can enter the license names in the following format- contoso:EnterprisePack,contoso:Flow_Free
Set Usage Location in Office 365
Before a license can be assigned to the users, they must have ‘Usage Location’. Else, you will receive a ‘Licence cannot be assigned to a user without a usage location specified’ error. To set usage location for Office 365 users, we have given the ‘LicenseUsageLocation’ param.
While running the license assignment use cases, you can specify the ‘LicenseUsageLocation’ param to set usage location to users whose usage location value is empty.
.\O365LicenseReportingAndManagement.ps1 -Action 7 –LicenseUsageLocation US
.\O365LicenseReportingAndManagement.ps1 –LicenseUsageLocation US
Unassign Licenses from Office 365 Users using PowerShell:
Identifying and reclaiming unused licenses help to optimize the license usage and reduce the license cost. We have covered the most requested license removal techniques below.
Remove All Licenses from a User:
When a user no longer need licenses or leaves the organization, you can remove all the assigned licenses from that user. By using the below format, you can remove all the licenses from a user account.
.\O365LicenseReportingAndManagement.ps1 -Action 8
After running the above format, the script will ask to enter the user’s identity to unassign the licenses. You can provide UserPrincipalName as an identity.
Remove All Office 365 Licenses for a List of Users in CSV:
When you want to regain the license(s) from former employees and inactive users, you can unassign the licenses in bulkby executing our script in the below format.
.\O365LicenseReportingAndManagement.ps1 -Action 9
The script will prompt for input CSV. After entering the file path, the script removes the license from user accounts mentioned in the input CSV. After the execution, you can refer “Office365_License_Removal_Log” file to know about the license removal status.
Remove Specific License from All Users:
You can choose this use case in the following scenarios.
- When you want to move from one license plan to another license plan. For e.g., E3 to E5.
- When you no longer use a specific license plan
To remove a specific license from all users,
.\O365LicenseReportingAndManagement.ps1 -Action 10
After running the above format, the script will ask for the license plan to be removed and then proceeds with license removal. In the end, you can refer to the license removal audit log file for the status.
Remove Licenses from Disabled Users:
Most organizations disable the departed users’ accounts instead of deleting them. To control cost and gain unused licenses, you can remove licenses from disabled users.
To remove all the licenses from all the disabled users, run the script as follows,
.\O365LicenseReportingAndManagement.ps1 -Action 11
You can refer to the log file to know the list of disabled users and their unassigned licenses.
Schedule Office 365 License Reports:
Instead of manually running the script, you can use Windows Task Scheduler to execute the script automatically at a pre-configured time.
To run the script as scheduled PowerShell task, follow the below format
.\O365LicenseReportingAndManagement.ps1 -Action 1 –UserName [email protected] -Password XX
If the admin account has MFA, you need to disable MFA based on the Conditional Access policy to make it work.
How to Get Office 365 License Reports in a Simple Way?
If you are tired of running PowerShell cmdlets or scripts, you can try AdminDroid Office 365 Reporting tool. The tool provides 20+ license reportsfree of cost to manage your organization’s license needs efficiently.
Additionally, AdminDroid provides over 100+ reports and a handful of dashboardscompletely for free. It includes reports on Users, Licenses, Groups, Group Members, Devices, Login Activities, Password Changes, License Changes, and more. The free version allows you to perform customization, scheduling, and exporting too. Download Free Office 365 reporting tool by AdminDroidand see how it helps you.
Each report provides AI-powered graphical analysis to gain insights and understand the data in a visually appealing manner.
Besides, AdminDroid Microsoft 365 reporting toolprovides 1500+ reportsto get detailed reports on various Office 365 services like Azure AD, Exchange Online, SharePoint Online, Microsoft Teams, OneDrive for Business, Streams, One Note, Yammer, etc.
I hope this blog will help you in managing Office 365 licenses and generating license reports. You can share your license management techniques with other admins and us through the comment section.
The post Office 365 License Reporting and Management using PowerShell appeared first on Office 365 Reports.