Get-MgmtGraphUserLicense
MgmtGraph: Audits license assignments for a Microsoft Graph user
#Requires -Version 5.1
#Requires -Modules Microsoft.Graph.Users
[CmdletBinding()]
Param (
[Parameter(Mandatory = $true, Position = 0)]
[string]$Identity
)
Process {
try {
$licenses = Get-MgUserLicenseDetail -UserId $Identity -All -ErrorAction Stop
$results = foreach ($lic in $licenses) {
[PSCustomObject]@{
SkuId = $lic.SkuId
SkuPartNumber = $lic.SkuPartNumber
ServicePlans = $lic.ServicePlans | ForEach-Object { $_.ServicePlanName }
Timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
}
}
Write-Output $results
}
catch {
throw
}
}Specifies the UserPrincipalName or ID of the user to audit.