Closed aigolang closed 6 months ago
`# ReportUserAssignedLicenses-MgGraph.PS1
$skuDataPath = "C:\temp\SkuDataComplete.csv" $servicePlanPath = "C:\temp\ServicePlanDataComplete.csv"
$CSVOutputFile = "C:\temp\Microsoft365LicensesReport.CSV" $ReportFile = "C:\temp\Microsoft365LicensesReport.html"
Connect-MgGraph -Scope "Directory.AccessAsUser.All, Directory.Read.All, AuditLog.Read.All"
[Array]$Skus = Get-MgSubscribedSku
$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
Just like this:
Direct assigned licenses seem to be working OK in my version. What exact changes did you want to make?
`# 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