Skip to content

Commit 6af8b42

Browse files
committed
fix: Intune policy template tweaks
Disable edit template for library synced templates Edit name/description will create a new template if synced Add clone template function Preserve package on edit template name
1 parent a068b09 commit 6af8b42

File tree

3 files changed

+84
-4
lines changed

3 files changed

+84
-4
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
function Invoke-ExecCloneTemplate {
2+
<#
3+
.FUNCTIONALITY
4+
Entrypoint,AnyTenant
5+
.ROLE
6+
CIPP.Core.ReadWrite
7+
#>
8+
param(
9+
$Request,
10+
$TriggerMetadata
11+
)
12+
13+
$GUID = $Request.Query.GUID ?? $Request.Body.GUID
14+
$Type = $Request.Query.Type ?? $Request.Body.Type
15+
16+
if ($GUID -and $Type) {
17+
$Table = Get-CIPPTable -tablename templates
18+
$Template = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq '$Type' and RowKey eq '$GUID'"
19+
20+
if ($Template) {
21+
$NewGuid = [guid]::NewGuid().ToString()
22+
$Template.RowKey = $NewGuid
23+
$Template.JSON = $Template.JSON -replace $GUID, $NewGuid
24+
$Template.Package = $null
25+
$Template.SHA = $null
26+
try {
27+
Add-CIPPAzDataTableEntity @Table -Entity $Template
28+
$body = @{
29+
Results = @{
30+
state = 'success'
31+
resultText = 'Template cloned successfully'
32+
}
33+
}
34+
} catch {
35+
$body = @{
36+
Results = @{
37+
state = 'error'
38+
resultText = 'Failed to clone template'
39+
details = Get-CIPPException -Exception $_
40+
}
41+
}
42+
}
43+
} else {
44+
$body = @{
45+
Results = @{
46+
state = 'error'
47+
resultText = 'Template not found'
48+
}
49+
}
50+
}
51+
} else {
52+
$body = @{
53+
Results = @{
54+
state = 'error'
55+
resultText = 'GUID or Type not provided'
56+
}
57+
}
58+
}
59+
return ([HttpResponseContext]@{
60+
StatusCode = [HttpStatusCode]::OK
61+
Body = $body
62+
})
63+
}

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/CIPP/Core/Invoke-ExecEditTemplate.ps1

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,30 @@ function Invoke-ExecEditTemplate {
1717

1818
if ($Type -eq 'IntuneTemplate') {
1919
Write-Host 'Intune Template'
20-
$OriginalTemplate = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'IntuneTemplate' and RowKey eq '$GUID'"
21-
$OriginalJSON = $OriginalTemplate.JSON
22-
$OriginalTemplate = ($OriginalJSON | ConvertFrom-Json -Depth 100)
20+
$Template = Get-CIPPAzDataTableEntity @Table -Filter "PartitionKey eq 'IntuneTemplate' and RowKey eq '$GUID'"
21+
$OriginalJSON = $Template.JSON
22+
23+
if ($Template.SHA) {
24+
$NewGuid = [guid]::NewGuid().ToString()
25+
} else {
26+
$NewGuid = $GUID
27+
}
2328
if ($Request.Body.parsedRAWJson) {
2429
$RawJSON = ConvertTo-Json -Compress -Depth 100 -InputObject $Request.Body.parsedRAWJson
2530
} else {
2631
$RawJSON = $OriginalJSON
2732
}
28-
Set-CIPPIntuneTemplate -RawJSON $RawJSON -GUID $GUID -DisplayName $Request.Body.displayName -Description $Request.Body.description -templateType $OriginalTemplate.Type -Headers $Request.Headers
33+
34+
$IntuneTemplate = @{
35+
GUID = $NewGuid
36+
RawJson = $RawJSON
37+
DisplayName = $Request.Body.displayName
38+
Description = $Request.Body.description
39+
templateType = $Template.Type
40+
Package = $Template.Package
41+
Headers = $Request.Headers
42+
}
43+
Set-CIPPIntuneTemplate @IntuneTemplate
2944
} else {
3045
$Table.Force = $true
3146
Add-CIPPAzDataTableEntity @Table -Entity @{

Modules/CIPPCore/Public/Set-CIPPIntuneTemplate.ps1

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ function Set-CIPPIntuneTemplate {
66
$DisplayName,
77
$Description,
88
$templateType,
9+
$Package,
910
$Headers
1011
)
1112
Write-Host "Received $DisplayName, $Description, $RawJSON, $templateType"
@@ -25,6 +26,7 @@ function Set-CIPPIntuneTemplate {
2526
JSON = "$object"
2627
RowKey = "$GUID"
2728
GUID = "$GUID"
29+
Package = "$Package"
2830
PartitionKey = 'IntuneTemplate'
2931
}
3032
Write-LogMessage -Headers $Headers -API $APINAME -message "Created intune policy template named $($Request.body.displayname) with GUID $GUID" -Sev 'Debug'

0 commit comments

Comments
 (0)