Skip to content

Commit

Permalink
fixes nesting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinTegelaar committed Jan 30, 2024
1 parent 849b57b commit 3c26927
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
14 changes: 6 additions & 8 deletions Modules/CIPPCore/Public/Entrypoints/Invoke-AddCATemplate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ Function Invoke-AddCATemplate {
try {
$GUID = (New-Guid).GUID
$JSON = if ($request.body.rawjson) {
([pscustomobject]$request.body.rawjson) | ConvertFrom-Json
}
else {
ConvertFrom-Json -InputObject ([pscustomobject]$request.body.rawjson)
} else {
([pscustomobject]$Request.body) | ForEach-Object {
$NonEmptyProperties = $_.psobject.Properties | Where-Object { $null -ne $_.Value } | Select-Object -ExpandProperty Name
$_ | Select-Object -Property $NonEmptyProperties
Expand All @@ -44,7 +43,7 @@ Function Invoke-AddCATemplate {

$JSON | Add-Member -NotePropertyName 'LocationInfo' -NotePropertyValue @($IncludeJSON, $ExcludeJSON)

$JSON = ($JSON | ConvertTo-Json -Depth 100)
$JSON = (ConvertTo-Json -Depth 100 -InputObject $JSON )
$Table = Get-CippTable -tablename 'templates'
$Table.Force = $true
Add-CIPPAzDataTableEntity @Table -Entity @{
Expand All @@ -53,12 +52,11 @@ Function Invoke-AddCATemplate {
PartitionKey = 'CATemplate'
GUID = "$GUID"
}
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created Transport Rule Template $($Request.body.name) with GUID $GUID" -Sev 'Debug'
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created CA Template $($Request.body.name) with GUID $GUID" -Sev 'Debug'
$body = [pscustomobject]@{'Results' = 'Successfully added template' }

}
catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Failed to create Transport Rule Template: $($_.Exception.Message)" -Sev 'Error'
} catch {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Failed to create CA Template: $($_.Exception.Message)" -Sev 'Error'
$body = [pscustomobject]@{'Results' = "Intune Template Deployment failed: $($_.Exception.Message)" }
}

Expand Down
5 changes: 3 additions & 2 deletions Modules/CIPPCore/Public/New-CIPPCAPolicy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ function New-CIPPCAPolicy {
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Matched a CA policy with the existing Named Location: $($location.displayName)" -Sev 'Info'

} else {
if ($location.countriesAndRegions) { $location.countriesAndRegions = @($location.countriesAndRegions) }
$Body = ConvertTo-Json -InputObject $Location
Write-Host "Trying to create named location with: $body"
$GraphRequest = New-GraphPOSTRequest -uri 'https://graph.microsoft.com/beta/identity/conditionalAccess/namedLocations' -body $body -Type POST -tenantid $tenantfilter
Write-LogMessage -user $request.headers.'x-ms-client-principal' -API $APINAME -message "Created new Named Location: $($location.displayName)" -Sev 'Info'
[pscustomobject]@{
Expand All @@ -83,10 +85,9 @@ function New-CIPPCAPolicy {
}
}
}
Write-Host 'here5'

foreach ($location in $JSONObj.conditions.locations.includeLocations) {
Write-Host "Replacting $location"
Write-Host "Replacing $location"
$lookup = $LocationLookupTable | Where-Object -Property name -EQ $location
Write-Host "Found $lookup"
if (!$lookup) { continue }
Expand Down

0 comments on commit 3c26927

Please sign in to comment.