You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Import-Module Microsoft.Graph.Users, Microsoft.Graph.Identity.DirectoryManagement
Connect to Microsoft Graph with required permissions
Connect-MgGraph -Scope User.read.all, DeviceManagementConfiguration.Read.All
Get your company name (replace with your organization's domain)
$CompanyName = (Get-MgOrganization | Select VerifiedDomains).verifieddomains | Where-Object { $_.IsDefault -eq "True" }
Get all users
$Users = Get-MgUser -all
Create a report
$Report = [System.Collections.Generic.List[Object]]::new()
Write-Host "Found $($users.count) users for $ ($CompanyName.Name)" -ForegroundColor Cyan
foreach ($user in $Users) {
Write-Host "Retrieving license info for $($User.DisplayName)" -ForegroundColor Yellow
if (Get-MgUserLicenseDetail -UserId $User.id) {
$licenses = (Get-MgUserLicenseDetail -UserId $User.id).SkuPartNumber -join ", "
Write-Host "Licenses found for $($User.DisplayName): $licenses" -ForegroundColor Cyan
$obj = [pscustomobject][ordered]@{
DisplayName = $user.DisplayName
UserPrincipalName = $user.UserPrincipalName
Licenses = $licenses
}
$report.Add($obj)
} else {
Write-Host "No licenses found for $($User.DisplayName)" -ForegroundColor Red
}
}
Export the report to a CSV file
$report | Export-CSV "C:\temp\licensedusers.csv" -NoTypeInformation
All script
Import-Module Microsoft.Graph.Users, Microsoft.Graph.Identity.DirectoryManagement$users.count) users for $ ($CompanyName.Name)" -ForegroundColor Cyan
Connect-MgGraph -Scope User.read.all, DeviceManagementConfiguration.Read.All
$CompanyName = (Get-MgOrganization | Select VerifiedDomains).verifieddomains | Where-Object { $_.IsDefault -eq "True" }
$Users = Get-MgUser -all
$Report = [System.Collections.Generic.List[Object]]::new()
Write-Host "Found $(
foreach ($user in $Users) {
Write-Host "Retrieving license info for $($User.DisplayName)" -ForegroundColor Yellow
if (Get-MgUserLicenseDetail -UserId $User.id) {
$licenses = (Get-MgUserLicenseDetail -UserId $User.id).SkuPartNumber -join ", "
Write-Host "Licenses found for $($User.DisplayName): $licenses" -ForegroundColor Cyan
$obj = [pscustomobject][ordered]@{
DisplayName = $user.DisplayName
UserPrincipalName = $user.UserPrincipalName
Licenses = $licenses
}
$report.Add($obj)
} else {
Write-Host "No licenses found for $($User.DisplayName)" -ForegroundColor Red
}
}
$report | Export-CSV "C:\temp\licensedusers.csv" -NoTypeInformation
Beta Was this translation helpful? Give feedback.
All reactions