12Knocksinna / Office365itpros

Office 365 for IT Pros PowerShell examples
MIT License
1.33k stars 577 forks source link

ReportUserAssignedLicenses-MgGraph.PS1 - Fixed a bug which the column "Direct assigned licenses" is empty. #104

Closed aigolang closed 6 months ago

aigolang commented 6 months ago

`# ReportUserAssignedLicenses-MgGraph.PS1

V1.8 11-Mar-2024 Fixed a bug which the column "Direct assigned licenses" is empty.

>>> Define Custom path at the begining >>>

$skuDataPath = "C:\temp\SkuDataComplete.csv" $servicePlanPath = "C:\temp\ServicePlanDataComplete.csv"

$CSVOutputFile = "C:\temp\Microsoft365LicensesReport.CSV" $ReportFile = "C:\temp\Microsoft365LicensesReport.html"

<<< Define Custom path at the begining <<<

Connect to the Graph, specifing the tenant and profile to use - Add your tenant identifier here

Connect-MgGraph -Scope "Directory.AccessAsUser.All, Directory.Read.All, AuditLog.Read.All"

[Array]$Skus = Get-MgSubscribedSku

$Skus | Select SkuId, SkuPartNumber | Export-Csv -NoTypeInformation $skuDataPath

$SPData = [System.Collections.Generic.List[Object]]::new() ForEach ($S in $Skus) { ForEach ($SP in $S.ServicePlans) { $SPLine = [PSCustomObject][Ordered]@{
ServicePlanId = $SP.ServicePlanId ServicePlanName = $SP.ServicePlanName ServicePlanDisplayName = $SP.ServicePlanName } $SPData.Add($SPLine) } } $SPData | Sort ServicePlanId -Unique | Export-csv $servicePlanPath -NoTypeInformation

aigolang commented 6 months ago

Just like this: image

12Knocksinna commented 6 months ago

Direct assigned licenses seem to be working OK in my version. What exact changes did you want to make?