Skip to content

Commit

Permalink
Add support to retrive all license assignments
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolonsky committed Jul 29, 2020
1 parent 3a9ade8 commit af06206
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
Binary file modified AzureADLicensing/AzureADLicensing.psd1
Binary file not shown.
32 changes: 26 additions & 6 deletions AzureADLicensing/AzureADLicensing.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,46 @@ 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 {

$baseUrl = "https://main.iam.ad.ext.azure.com/api/"

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
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,15 @@ Remove license assignment:

<pre>Remove-AADGroupLicenseAssignment -groupId "a5e95316-1c03-44d7-afac-efd0e788122c" -accountSkuId "nicolasuter:FLOW_FREE"</pre>

Get license assignments:
Get license assignments for a specific group:

<pre>
Get-AADGroupLicenseAssignment -groupId "a5e95316-1c03-44d7-afac-efd0e788122c"
</pre>

Get all group based licensing assignments:

<pre>
Get-AADGroupLicenseAssignment -All
</pre>

0 comments on commit af06206

Please sign in to comment.