Skip to content

Commit 53ade39

Browse files
committed
Fix license processing
1 parent 79a18ed commit 53ade39

File tree

1 file changed

+12
-36
lines changed

1 file changed

+12
-36
lines changed

Runbooks/CloudAdmin_0100__New-CloudAdministrator-Account.ps1

Lines changed: 12 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<#PSScriptInfo
2-
.VERSION 1.5.0
2+
.VERSION 1.5.1
33
.GUID 03b78b5d-1e83-44bc-83ce-a5c0f101461b
44
.AUTHOR Julian Pawlowski
55
.COMPANYNAME Workoho GmbH
@@ -12,9 +12,9 @@
1212
.REQUIREDSCRIPTS CloudAdmin_0000__Common_0000__Get-ConfigurationConstants.ps1
1313
.EXTERNALSCRIPTDEPENDENCIES https://github.com/workoho/AzAuto-Common-Runbook-FW
1414
.RELEASENOTES
15-
Version 1.5.0 (2024-06-17)
16-
- Rewrite to use Common_0001__Invoke-MgGraphRequest.ps1 for all Microsoft Graph API calls.
17-
- Remove all Microsoft.Graph module dependencies, except Microsoft.Graph.Authentication.
15+
Version 1.5.1 (2024-06-23)
16+
- Fix license processing
17+
- Remove free license validation when updating existing accounts
1818
#>
1919

2020
<#
@@ -541,7 +541,7 @@ $SkuPartNumberWithExchangeServicePlan = $null
541541
@(($LicenseSkuPartNumber_Tier0 -split ' '); ($LicenseSkuPartNumber_Tier1 -split ' '); ($LicenseSkuPartNumber_Tier2 -split ' ')) | Where-Object { -Not [string]::IsNullOrEmpty($_) } | Select-Object -Unique | & {
542542
process {
543543
$SkuPartNumber = $_
544-
$Sku = $TenantSubscriptions | Where-Object { $_.SkuPartNumber -eq $SkuPartNumber } | Select-Object -Property Sku*, ServicePlans
544+
$Sku = $TenantSubscriptions | Where-Object { $_.SkuPartNumber -eq $SkuPartNumber }
545545
if (-Not $Sku) {
546546
Throw "[LicenseExistanceValidation]: - License SkuPartNumber $SkuPartNumber is not available to this tenant. Licenses must be purchased before creating Cloud Administrator accounts."
547547
}
@@ -2177,7 +2177,7 @@ Function ProcessReferralUser ($ReferralUserId, $LocalUserId, $Tier, $UserPhotoUr
21772177
}
21782178
else {
21792179
#region License Availability Validation Before New Account Creation ------------
2180-
$TenantSubscriptions = (./Common_0001__Invoke-MgGraphRequest.ps1 @{ Uri = '/v1.0/subscribedSkus'; ErrorAction = 'Stop'; Verbose = $false; Debug = $false }).value | Where-Object { $_.SkuPartNumber -in $LicenseSkuPartNumbers } | Select-Object -Property Sku*, ConsumedUnits, ServicePlans, PrepaidUnits | & {
2180+
$TenantSubscriptions = (./Common_0001__Invoke-MgGraphRequest.ps1 @{ Uri = '/v1.0/subscribedSkus'; ErrorAction = 'Stop'; Verbose = $false; Debug = $false }).value | Where-Object { $_.SkuPartNumber -in $LicenseSkuPartNumbers } | & {
21812181
process {
21822182
if ($_.ConsumedUnits -ge $_.PrepaidUnits.Enabled) {
21832183
[void] $script:returnError.Add(( ./Common_0000__Write-Error.ps1 @{
@@ -2403,34 +2403,6 @@ Function ProcessReferralUser ($ReferralUserId, $LocalUserId, $Tier, $UserPhotoUr
24032403
}
24042404
#endregion ---------------------------------------------------------------------
24052405

2406-
#region License Availability Validation For Pre-Existing Account ---------------
2407-
if (-Not $TenantSubscriptions) {
2408-
$TenantSubscriptions = (./Common_0001__Invoke-MgGraphRequest.ps1 @{ Uri = '/v1.0/subscribedSkus'; ErrorAction = 'Stop'; Verbose = $false; Debug = $false }).value | Where-Object { $_.SkuPartNumber -in $LicenseSkuPartNumbers } | Select-Object -Property Sku*, ConsumedUnits, ServicePlans, PrepaidUnits | & {
2409-
process {
2410-
if ($_.ConsumedUnits -ge $_.PrepaidUnits.Enabled) {
2411-
[void] $script:returnError.Add(( ./Common_0000__Write-Error.ps1 @{
2412-
Message = "${ReferralUserId}: License SkuPartNumber $($_.SkuPartNumber) has run out of free licenses."
2413-
ErrorId = '503'
2414-
Category = 'LimitsExceeded'
2415-
TargetName = $refUserObj.userPrincipalName
2416-
TargetObject = $refUserObj.id
2417-
TargetType = 'UserId'
2418-
RecommendedAction = 'Purchase additional licenses to create new Cloud Administrator accounts.'
2419-
CategoryActivity = 'License Availability Validation'
2420-
CategoryReason = "License SkuPartNumber $($_.SkuPartNumber) has run out of free licenses."
2421-
}))
2422-
$script:persistentError = $true
2423-
}
2424-
else {
2425-
Write-Verbose "[ProcessReferralUserDedicatedAccountUpdate]: - License SkuPartNumber $($_.SkuPartNumber) has at least 1 free license available to continue"
2426-
$_
2427-
}
2428-
}
2429-
}
2430-
if ($persistentError) { return }
2431-
}
2432-
#endregion ---------------------------------------------------------------------
2433-
24342406
#region Direct License Assignment ----------------------------------------------
24352407
if (-Not $LicenseGroupObj) {
24362408
Write-Verbose "[ProcessReferralUserDedicatedAccountDirectLicensing]: - Implying direct license assignment is required as no GroupId was provided for group-based licensing."
@@ -2450,9 +2422,13 @@ Function ProcessReferralUser ($ReferralUserId, $LocalUserId, $Tier, $UserPhotoUr
24502422
SkuId = $Sku.SkuId
24512423
}
24522424
if ($SkuPartNumber -eq $SkuPartNumberWithExchangeServicePlan) {
2453-
$license.DisabledPlans = $Sku.ServicePlans | Where-Object { $_.AppliesTo -eq 'User' -and $_.ServicePlanName -NotMatch 'EXCHANGE' } | Select-Object -ExpandProperty ServicePlanId
2425+
$disabledPlans = [System.Collections.ArrayList]::new()
2426+
$Sku.ServicePlans | Where-Object { $_.AppliesTo -eq 'User' -and $_.ServicePlanName -NotMatch 'EXCHANGE' } | ForEach-Object {
2427+
[void] $disabledPlans.Add($_.ServicePlanId)
2428+
}
2429+
$license.DisabledPlans = $disabledPlans
24542430
}
2455-
$params.AddLicenses += $license
2431+
[void] $params.AddLicenses.Add($license)
24562432
}
24572433
}
24582434
}

0 commit comments

Comments
 (0)