Skip to content

Commit 983a8bd

Browse files
authored
Merge pull request #422 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 0dcb509 + cdd9bbc commit 983a8bd

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using namespace System.Net
2+
3+
function Invoke-ExecDriftClone {
4+
<#
5+
.FUNCTIONALITY
6+
Entrypoint,AnyTenant
7+
.ROLE
8+
Tenant.Standards.ReadWrite
9+
#>
10+
[CmdletBinding()]
11+
param($Request, $TriggerMetadata)
12+
13+
try {
14+
$TemplateId = $Request.Body.id
15+
16+
if (-not $TemplateId) {
17+
$Results = [pscustomobject]@{
18+
'Results' = 'Template ID is required'
19+
'Success' = $false
20+
}
21+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
22+
StatusCode = [HttpStatusCode]::BadRequest
23+
Body = $Results
24+
})
25+
return
26+
}
27+
$CloneResult = New-CippStandardsDriftClone -TemplateId $TemplateId -UpgradeToDrift -Headers $Request.Headers
28+
$Results = [pscustomobject]@{
29+
'Results' = $CloneResult
30+
'Success' = $true
31+
}
32+
33+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
34+
StatusCode = [HttpStatusCode]::OK
35+
Body = $Results
36+
})
37+
} catch {
38+
$Results = [pscustomobject]@{
39+
'Results' = "Failed to create drift clone: $($_.Exception.Message)"
40+
'Success' = $false
41+
}
42+
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
43+
StatusCode = [HttpStatusCode]::InternalServerError
44+
Body = $Results
45+
})
46+
}
47+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

Modules/CIPPCore/Public/Send-CIPPAlert.ps1

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ function Send-CIPPAlert {
2222
Write-Information 'Trying to send email'
2323
try {
2424
if ($Config.email -like '*@*' -or $altEmail -like '*@*') {
25-
$Recipients = if ($AltEmail) { $AltEmail }
26-
else {
25+
$Recipients = if ($AltEmail) {
26+
[pscustomobject]@{EmailAddress = @{Address = $AltEmail } }
27+
} else {
2728
$Config.email.split($(if ($Config.email -like '*,*') { ',' } else { ';' })).trim() | ForEach-Object { if ($_ -like '*@*') { [pscustomobject]@{EmailAddress = @{Address = $_ } } } }
2829
}
2930
$PowerShellBody = [PSCustomObject]@{

0 commit comments

Comments
 (0)