Skip to content

Commit 29a7c65

Browse files
committed
Feat: Update Set-CIPPAssignedPolicy to dynamically set assignment property names based on type
1 parent 75ddf7b commit 29a7c65

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Modules/CIPPCore/Public/Set-CIPPAssignedPolicy.ps1

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,12 +195,17 @@ function Set-CIPPAssignedPolicy {
195195
$FinalAssignments.Add($newAssignment)
196196
}
197197

198-
$assignmentsObject = [PSCustomObject]@{
199-
# assignments = @($FinalAssignments.ToArray())
200-
assignments = @($FinalAssignments)
198+
# Determine the assignment property name based on type
199+
$AssignmentPropertyName = switch ($Type) {
200+
'deviceHealthScripts' { 'deviceHealthScriptAssignments' }
201+
'deviceManagementScripts' { 'deviceManagementScriptAssignments' }
202+
'deviceShellScripts' { 'deviceManagementScriptAssignments' }
203+
default { 'assignments' }
201204
}
202205

203-
$AssignJSON = $assignmentsObject | ConvertTo-Json -Depth 10 -Compress
206+
$assignmentsObject = @{ $AssignmentPropertyName = @($FinalAssignments) }
207+
208+
$AssignJSON = ConvertTo-Json -InputObject $assignmentsObject -Depth 10 -Compress
204209
if ($PSCmdlet.ShouldProcess($GroupName, "Assigning policy $PolicyId")) {
205210
$uri = "https://graph.microsoft.com/beta/$($PlatformType)/$Type('$($PolicyId)')/assign"
206211
$null = New-GraphPOSTRequest -uri $uri -tenantid $TenantFilter -type POST -body $AssignJSON

0 commit comments

Comments
 (0)