|
| 1 | +function New-CippStandardsDriftClone { |
| 2 | + [CmdletBinding()] |
| 3 | + param ( |
| 4 | + [Parameter(Mandatory)][string]$TemplateId, |
| 5 | + [Parameter(Mandatory)][switch]$UpgradeToDrift, |
| 6 | + $Headers |
| 7 | + ) |
| 8 | + |
| 9 | + $Table = Get-CippTable -tablename 'templates' |
| 10 | + $Filter = "PartitionKey eq 'StandardsTemplateV2' and RowKey eq '$TemplateId'" |
| 11 | + $Entity = Get-CIPPAzDataTableEntity @Table -Filter $Filter |
| 12 | + $data = $Entity.JSON | ConvertFrom-Json |
| 13 | + $data.excludedTenants = @() #blank excluded Tenants |
| 14 | + $data.tenantFilter = @(@{ value = 'Copied Standard'; label = 'Copied Standard' }) |
| 15 | + $data.GUID = [guid]::NewGuid().ToString() |
| 16 | + $data.templateName = "$($data.templateName) (Drift Clone)" |
| 17 | + if ($UpgradeToDrift) { |
| 18 | + try { |
| 19 | + $data | Add-Member -MemberType NoteProperty -Name 'type' -Value 'drift' -Force |
| 20 | + if ($null -ne $data.standards) { |
| 21 | + foreach ($prop in $data.standards.PSObject.Properties) { |
| 22 | + $actions = $prop.Value.action |
| 23 | + if ($actions -and $actions.Count -gt 0) { |
| 24 | + if ($actions | Where-Object { $_.value -eq 'remediate' }) { |
| 25 | + $prop.Value | Add-Member -MemberType NoteProperty -Name 'autoRemediate' -Value $true -Force |
| 26 | + } |
| 27 | + $prop.Value.action = @(@{ 'label' = 'Report'; 'value' = 'Report' }) |
| 28 | + } |
| 29 | + } |
| 30 | + } |
| 31 | + $Entity.JSON = "$(ConvertTo-Json -InputObject $data -Compress -Depth 100)" |
| 32 | + $Entity.RowKey = "$($data.GUID)" |
| 33 | + $Entity.GUID = $data.GUID |
| 34 | + $update = Add-CIPPAzDataTableEntity @Table -Entity $Entity -Force |
| 35 | + return 'Clone Completed successfully' |
| 36 | + } catch { |
| 37 | + return "Failed to Clone template to Drift Template: $_" |
| 38 | + } |
| 39 | + } |
| 40 | +} |
0 commit comments