Skip to content

Commit c6fb7dd

Browse files
authored
Merge pull request #471 from KelvinTegelaar/dev
[pull] dev from KelvinTegelaar:dev
2 parents 87e9f9f + 72c890c commit c6fb7dd

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

Modules/CIPPCore/Public/Entrypoints/HTTP Functions/Tenant/Administration/Invoke-ExecUpdateSecureScore.ps1

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using namespace System.Net
22

3-
Function Invoke-ExecUpdateSecureScore {
3+
function Invoke-ExecUpdateSecureScore {
44
<#
55
.FUNCTIONALITY
66
Entrypoint
@@ -17,23 +17,28 @@ Function Invoke-ExecUpdateSecureScore {
1717
# Interact with query parameters or the body of the request.
1818
$TenantFilter = $Request.Body.TenantFilter
1919
$ControlName = $Request.Body.ControlName
20-
$Body = @{
21-
comment = $Request.Body.reason
22-
state = $Request.Body.resolutionType.value
23-
vendorInformation = $Request.Body.vendorInformation
24-
}
25-
try {
26-
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/security/secureScoreControlProfiles/$ControlName" -tenantid $TenantFilter -type PATCH -Body (ConvertTo-Json -InputObject $Body -Compress)
27-
$StatusCode = [HttpStatusCode]::OK
28-
$Result = "Successfully set control $ControlName to $($Body.state)"
29-
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -Sev 'Info'
30-
} catch {
31-
$ErrorMessage = Get-CippException -Exception $_
32-
$Result = "Failed to set control $ControlName to $($Body.state). Error: $($ErrorMessage.NormalizedError)"
33-
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -Sev Error -LogData $ErrorMessage
34-
$StatusCode = [HttpStatusCode]::InternalServerError
35-
}
3620

21+
if ($ControlName -match '^scid_') {
22+
$Result = 'Defender controls cannot be updated via this API. Please use the Microsoft 365 Defender portal to update these controls.'
23+
$StatusCode = [HttpStatusCode]::BadRequest
24+
} else {
25+
$Body = @{
26+
comment = $Request.Body.reason
27+
state = $Request.Body.resolutionType.value
28+
vendorInformation = $Request.Body.vendorInformation
29+
}
30+
try {
31+
$null = New-GraphPostRequest -uri "https://graph.microsoft.com/beta/security/secureScoreControlProfiles/$ControlName" -tenantid $TenantFilter -type PATCH -Body (ConvertTo-Json -InputObject $Body -Compress)
32+
$StatusCode = [HttpStatusCode]::OK
33+
$Result = "Successfully set control $ControlName to $($Body.state)"
34+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -Sev 'Info'
35+
} catch {
36+
$ErrorMessage = Get-CippException -Exception $_
37+
$Result = "Failed to set control $ControlName to $($Body.state). Error: $($ErrorMessage.NormalizedError)"
38+
Write-LogMessage -headers $Headers -API $APIName -tenant $TenantFilter -message $Result -Sev Error -LogData $ErrorMessage
39+
$StatusCode = [HttpStatusCode]::InternalServerError
40+
}
41+
}
3742
# Associate values to output bindings by calling 'Push-OutputBinding'.
3843
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
3944
StatusCode = $StatusCode

0 commit comments

Comments
 (0)