From af062063aebdd6b5ab15ee5693805b4650a6acd8 Mon Sep 17 00:00:00 2001 From: Nicola Suter Date: Wed, 29 Jul 2020 16:38:24 +0200 Subject: [PATCH] Add support to retrive all license assignments --- AzureADLicensing/AzureADLicensing.psd1 | Bin 8928 -> 8928 bytes AzureADLicensing/AzureADLicensing.psm1 | 32 ++++++++++++++++++++----- README.md | 9 ++++++- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/AzureADLicensing/AzureADLicensing.psd1 b/AzureADLicensing/AzureADLicensing.psd1 index 58ec3d7005e33c554d5c66fc7c44fdc7fddef7ea..446475e0278f0f6da07d07bbce92a6b8f3d45ea9 100644 GIT binary patch delta 14 VcmaFh`oMLA6%(V;W^1OU3IHum1s?za delta 14 VcmaFh`oMLA6%(W3W^1OU3IHug1s(tZ diff --git a/AzureADLicensing/AzureADLicensing.psm1 b/AzureADLicensing/AzureADLicensing.psm1 index 09411fa..84536b8 100644 --- a/AzureADLicensing/AzureADLicensing.psm1 +++ b/AzureADLicensing/AzureADLicensing.psm1 @@ -27,13 +27,17 @@ function Get-AADLicenseSku { } } } -} +} function Get-AADGroupLicenseAssignment { [cmdletbinding()] param( - [Parameter(Mandatory, HelpMessage = "ID of the Azure AD group")] - [String]$groupId + [Parameter(Mandatory, HelpMessage = "ID of the Azure AD group", ParameterSetName = "Single")] + [String]$groupId, + + [Parameter(Mandatory, HelpMessage = "Retrieves all Group Based License Assignments", ParameterSetName = "All")] + [switch] + $All ) process { @@ -41,12 +45,28 @@ function Get-AADGroupLicenseAssignment { try { - $request = Invoke-WebRequest -Method Get -Uri $($baseUrl + "AccountSkus/Group/$groupId") -Headers $(Get-AuthToken) + if ($All.IsPresent) { - $requestContent = $request | ConvertFrom-Json + $accountSkus = Get-AADLicenseSku + $rep = @() - return $requestContent + foreach ($sku in $accountSkus){ + $request = Invoke-WebRequest -Method Get -Uri $($baseUrl + "AccountSkus/GroupAssignments?accountSkuID=$($sku.accountSkuId)&nextLink=&searchText=&sortOrder=undefined") -Headers $(Get-AuthToken) + $requestContent = $request | ConvertFrom-Json + + $rep += [PSCustomObject]@{ + Name = $sku.Name + LicensedGroups = $requestContent.items + } + } + return $rep + + }else { + $request = Invoke-WebRequest -Method Get -Uri $($baseUrl + "AccountSkus/Group/$groupId") -Headers $(Get-AuthToken) + $requestContent = $request | ConvertFrom-Json + return $requestContent + } } catch { # convert the error message if it appears to be JSON diff --git a/README.md b/README.md index 3bcc05f..dc4f4b8 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,15 @@ Remove license assignment:
Remove-AADGroupLicenseAssignment -groupId "a5e95316-1c03-44d7-afac-efd0e788122c" -accountSkuId "nicolasuter:FLOW_FREE"
-Get license assignments: +Get license assignments for a specific group:
 Get-AADGroupLicenseAssignment -groupId "a5e95316-1c03-44d7-afac-efd0e788122c"
 
+ +Get all group based licensing assignments: + +
+Get-AADGroupLicenseAssignment -All
+
+