Skip to content

Commit 784cff5

Browse files
committed
fix(intune): preserve @odata.type on synced App Protection templates
Templates synced from a gold tenant fetch App Protection policies via their concrete type URL (e.g. androidManagedAppProtections('id')), and Graph omits @odata.type from those responses. The stored RAWJson then lacks @odata.type, so Set-CIPPIntunePolicy built the deploy URL as deviceAppManagement/s and Graph returned "Resource not found for the segment 's'.". Re-add @odata.type from the known ODataType when Graph omits it, and fail with a clear error on deploy when a stored template still has no @odata.type.
1 parent b4133f8 commit 784cff5

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

Modules/CIPPCore/Public/New-CIPPIntuneTemplate.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ function New-CIPPIntuneTemplate {
4747
default { 'managedAppPolicies' }
4848
}
4949
$Template = New-GraphGetRequest -uri "https://graph.microsoft.com/beta/deviceAppManagement/$($AppProtectionUrl)('$($ID)')" -tenantid $TenantFilter
50+
if ($ODataType -and !$Template.'@odata.type') {
51+
# Graph omits @odata.type when an entity is fetched via its concrete type URL, but Set-CIPPIntunePolicy derives the deploy URL from it
52+
if ($ODataType -notmatch '^#') { $ODataType = "#$ODataType" }
53+
$null = $Template | Add-Member -MemberType NoteProperty -Name '@odata.type' -Value $ODataType -Force
54+
}
5055
$DisplayName = $Template.displayName
5156
$TemplateJson = ConvertTo-Json -InputObject $Template -Depth 100 -Compress
5257
}

Modules/CIPPCore/Public/Set-CIPPIntunePolicy.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ function Set-CIPPIntunePolicy {
2727
'AppProtection' {
2828
$PlatformType = 'deviceAppManagement'
2929
$TemplateType = ($RawJSON | ConvertFrom-Json).'@odata.type' -replace '#microsoft.graph.', ''
30+
if ([string]::IsNullOrWhiteSpace($TemplateType)) {
31+
throw "App Protection template '$DisplayName' does not contain @odata.type, so the policy type cannot be determined. Recreate the template or re-run the template sync to include @odata.type."
32+
}
3033
$PolicyFile = $RawJSON | ConvertFrom-Json
3134
$Null = $PolicyFile | Add-Member -MemberType NoteProperty -Name 'description' -Value $Description -Force
3235
$null = $PolicyFile | Add-Member -MemberType NoteProperty -Name 'displayName' -Value $DisplayName -Force

0 commit comments

Comments
 (0)