Forum Discussion

coxygt's avatar
coxygt
Brass Contributor
Apr 12, 2022

Group Based Licensing in 365

So I have recently been setting up GBL on my tenant, I am trying to run a script so I can check all licenses applied to a SKU, I need to see the UPN, Sku (Product Name), If the license is directly assigned or if it's assigned by a group, if by a group, what group (name)?

 

I found this script online yesterday, it worked ok last yesterday, but today, the direct or group assigned is blank, no changes have been made.

 

$skuId = "CompanyName:POWER_BI_PRO"

#find all users that have the SKU license assigned
$details = Get-MsolUser -All | where {$_.isLicensed -eq $true -and $_.Licenses.AccountSKUID -eq $skuId} | select `
    UserPrincipalName, `
    @{Name="SkuId";Expression={$skuId}}, `
    @{Name="AssignedDirectly";Expression={(UserHasLicenseAssignedDirectly $skuId)}}, `
    @{Name="AssignedFromGroup";Expression={(UserHasLicenseAssignedFromGroup $skuId)}}
    $details | export-csv -path "c:\temp\ps output\$file" -NoTypeInformation
 
Anyone have a script or can provide the missing elements to complete this?
  • farismalaeb's avatar
    farismalaeb
    Steel Contributor

    coxygt 

    I advise you to recopy the code from the source. You missed adding the function, but I search it and get it. 

    PowerShell and Graph examples for group-based licensing in Azure AD 

    The code works fine for me.

    Try to call the function alone and pass the user ID and the SKU and see the return will work or not.

    UserHasLicenseAssignedDirectly -user "Email address removed" -skuId 'Orgname:SPE_E5'

    Also it can be due to an incorrect modification in the select statement, which cause the result to be blank

    • rah1m's avatar
      rah1m
      Copper Contributor
      I had the same issue coping the code adds addtional symbols ' - remove them then scipt works fine

Resources