Skip to content

Get-UserLicense

Azure AD: Retrieves license details for a user

#Requires -Version 5.1
#Requires -Modules AzureAD

[CmdletBinding()]
Param(
    [Parameter(Mandatory = $true)]
    [string]$UserObjectId
)

Process {
    try {
        $licenses = Get-AzureADUserLicenseDetail -ObjectId $UserObjectId -ErrorAction Stop | Select-Object SkuId, SkuPartNumber

        if ($null -ne $licenses) {
            foreach ($item in $licenses) {
                $item | Add-Member -NotePropertyName Timestamp -NotePropertyValue (Get-Date -Format "yyyy-MM-dd HH:mm:ss") -PassThru -Force
            }
        }
    }
    catch { throw }
}

UPN or ObjectId of the user in Azure AD

An interactive directory of PowerShell scripts.