INTRODUCTION:
Managing Microsoft 365 licenses effectively is crucial for organizations to ensure compliance and avoid unnecessary costs. PowerShell provides a straightforward way to identify licensed and unlicensed users within your tenant. With just a few commands, you can gain insights into your license usage, streamline administration, and make informed decisions about license allocation. This guide will help you get started with PowerShell to manage your Microsoft 365 licensing efficiently.
STEP 1:
Open Windows Powershell
Open Windows Powershell As Administrator.
STEP 2:
Microsoft Graph Powershell
- To Install Microsoft Graph Powershell, Put The Command. [ Install-Module -Name Microsoft.Graph ]
- To Check Microsoft Graph Version. [ Get-InstalledModule Microsoft.Graph ]
STEP 3:
To View What Modules Are Installed, Put The Command. [ Get-InstalledModule ]
STEP 4:
Microsoft Graph
Connect The Microsoft Graph, Put The Command. [ Connect-Graph -Scopes User.Read.All, Organization.Read.All ]
STEP 5:
Find Licensed User
- To Find Licensed User, Put The Command. [ Get-MgUser -Filter ‘assignedLicenses/$count ne 0’ -ConsistencyLevel eventual -CountVariable licensedUserCount -All -Select UserPrincipalName,DisplayName,AssignedLicenses | Format-Table -Property UserPrincipalName,DisplayName,AssignedLicenses ]
- To Find Number Of Licensed Users, Use This Command. [ Write-Host “Found $licensedUserCount licensed users.” ]
STEP 6:
Find UnLicensed User
- To Find UnLicensed User, Put The Command. [ Get-MgUser -Filter ‘assignedLicenses/$count eq 0’ -ConsistencyLevel eventual -CountVariable unlicensedUserCount -All ]
- To Find Number Of UnLicensed Users, Use This Command. [ Write-Host “Found $unlicensedUserCount unlicensed users.” ]
STEP 7:
Find Without An Assigned License Excluding Guests
- To Find Without An Assigned License Excluding Guests. [ Get-MgUser -Filter “assignedLicenses/`$count eq 0 and userType eq ‘Member'” -ConsistencyLevel eventual -CountVariable unlicensedUserCount -All ]
- To Find Number Of UnLicensed Users (Excluding Guests), Use This Command. [ Write-Host “Found $unlicensedUserCount unlicensed users (excluding guests).” ]
CONCLUSION:
Identifying licensed and unlicensed users in Microsoft 365 using PowerShell is a powerful way to manage your organization’s resources effectively. By automating the process, you can ensure compliance, optimize license usage, and reduce costs. Regular audits using these scripts will help maintain an organized and efficient Microsoft 365 environment.