Skip to content

Commit e33b6f3

Browse files
committed
Fix: Update assignment mode handling and improve existing assignment deduplication logic
1 parent 7464743 commit e33b6f3

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Endpoint/Applications/Invoke-ExecAssignApp.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function Invoke-ExecAssignApp {
2020
$AppType = $Request.Query.AppType ?? $Request.Body.AppType
2121
$GroupNamesRaw = $Request.Query.GroupNames ?? $Request.Body.GroupNames
2222
$GroupIdsRaw = $Request.Query.GroupIds ?? $Request.Body.GroupIds
23-
$AssignmentMode = $Request.Query.AssignmentMode ?? $Request.Body.AssignmentMode
23+
$AssignmentMode = $Request.Body.assignmentMode
2424

2525
$Intent = if ([string]::IsNullOrWhiteSpace($Intent)) { 'Required' } else { $Intent }
2626

@@ -58,7 +58,7 @@ function Invoke-ExecAssignApp {
5858
# Try to get the application type if not provided. Mostly just useful for ppl using the API that dont know the application type.
5959
if (-not $AppType) {
6060
try {
61-
$AppMetadata = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$appFilter?`$select=id,@odata.type" -tenantid $TenantFilter
61+
$AppMetadata = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$appFilter" -tenantid $TenantFilter
6262
$odataType = $AppMetadata.'@odata.type'
6363
if ($odataType) {
6464
$AppType = ($odataType -replace '#microsoft.graph.', '') -replace 'App$'

Modules/CIPPCore/Public/Set-CIPPAssignedApplication.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,18 @@ function Set-CIPPAssignedApplication {
128128
# Deduplicate current assignments so the new ones override existing ones
129129
if ($ExistingAssignments) {
130130
$ExistingAssignments = $ExistingAssignments | ForEach-Object {
131-
if ($_.target.groupId -notin $MobileAppAssignment.target.groupId) {
132-
$_
131+
$ExistingAssignment = $_
132+
switch ($ExistingAssignment.target.'@odata.type') {
133+
'#microsoft.graph.groupAssignmentTarget' {
134+
if ($ExistingAssignment.target.groupId -notin $MobileAppAssignment.target.groupId) {
135+
$ExistingAssignment
136+
}
137+
}
138+
default {
139+
if ($ExistingAssignment.target.'@odata.type' -notin $MobileAppAssignment.target.'@odata.type') {
140+
$ExistingAssignment
141+
}
142+
}
133143
}
134144
}
135145
}
@@ -164,6 +174,7 @@ function Set-CIPPAssignedApplication {
164174
}
165175
if ($PSCmdlet.ShouldProcess($GroupName, "Assigning Application $ApplicationId")) {
166176
Start-Sleep -Seconds 1
177+
# Write-Information (ConvertTo-Json $DefaultAssignmentObject -Depth 10)
167178
$null = New-GraphPOSTRequest -uri "https://graph.microsoft.com/beta/deviceAppManagement/mobileApps/$($ApplicationId)/assign" -tenantid $TenantFilter -type POST -body ($DefaultAssignmentObject | ConvertTo-Json -Compress -Depth 10)
168179
Write-LogMessage -headers $Headers -API $APIName -message "Assigned Application $ApplicationId to $($GroupName)" -Sev 'Info' -tenant $TenantFilter
169180
}

0 commit comments

Comments
 (0)