Skip to content

Commit 925b6bc

Browse files
fix bulk assign licenses
1 parent e8d61cc commit 925b6bc

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Identity/Administration/Users/Invoke-AddUserBulk.ps1

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,9 @@ function Invoke-AddUserBulk {
6767
if ($UsageLocation) {
6868
$UserBody.usageLocation = $UsageLocation.value ?? $UsageLocation
6969
Write-Information "- Usage location set to $($UsageLocation.label ?? $UsageLocation)"
70-
if ($AssignedLicenses) {
71-
$GuidPattern = '([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})'
72-
$LicenseSkus = $AssignedLicenses.value ?? $AssignedLicenses | Where-Object { $_ -match $GuidPattern }
73-
if (($LicenseSkus | Measure-Object).Count -gt 0) {
74-
Write-Information "- Assigned licenses set to $(($AssignedLicenses.label ?? $AssignedLicenses) -join ', ')"
75-
$Licenses = foreach ($Sku in $LicenseSkus) {
76-
[PSCustomObject]@{
77-
skuId = $Sku
78-
}
79-
}
80-
$UserBody.assignedLicenses = @($Licenses)
81-
}
82-
}
8370
}
8471

72+
8573
# Convert businessPhones to array if not null or empty
8674
if (![string]::IsNullOrEmpty($User.businessPhones)) {
8775
$UserBody.businessPhones = @($User.businessPhones)
@@ -137,6 +125,11 @@ function Invoke-AddUserBulk {
137125
})
138126
} else {
139127
$Message = $Messages.Where({ $_.id -eq $BulkResult.id })
128+
if ($AssignedLicenses) {
129+
$GuidPattern = '([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})'
130+
$LicenseSkus = $AssignedLicenses.value ?? $AssignedLicenses | Where-Object { $_ -match $GuidPattern }
131+
Set-CIPPUserLicense -User $BulkResult.id -AddLicenses $LicenseSkus
132+
}
140133
$Results.Add(@{
141134
resultText = $Message.resultText
142135
state = 'success'

0 commit comments

Comments
 (0)