Framework/Models/SubscriptionCore/AzureSecurityCenter.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Set-StrictMode -Version Latest 

class AzureSecurityCenter
{
    [PSObject] $Policies
    [PSObject] $Alerts
    [PSObject] $Tasks
    
    hidden static [PSObject] GetASCAlerts([PSObject] $alertObjects)
    {
        $activeAlerts =@()

        if($null -ne $alertObjects -and ($alertObjects | Measure-Object).Count -gt 0)
        {                
            $alertObjects | ForEach-Object { 
                $out = "" | Select-Object AlertDisplayName, AlertName, Description, State, ReportedTimeUTC, ReportedSeverity, RemediationSteps
                Set-Variable -Name AlertDisplayName -Value $_.properties.alertDisplayName        
                Set-Variable -Name AlertName -Value $_.properties.alertName
                Set-Variable -Name Description -Value $_.properties.description
                Set-Variable -Name State -Value $_.properties.state
                Set-Variable -Name ReportedTimeUTC -Value $_.properties.reportedTimeUtc
                Set-Variable -Name ReportedSeverity -Value $_.properties.reportedSeverity
                Set-Variable -Name RemediationSteps -Value $_.properties.remediationSteps

                $out.AlertDisplayName = $AlertDisplayName
                $out.AlertName = $AlertName
                $out.Description = $Description
                $out.State = $State
                $out.ReportedTimeUTC = $ReportedTimeUTC
                $out.ReportedSeverity = $ReportedSeverity
                $out.RemediationSteps = $RemediationSteps
                $activeAlerts += $out
            }
        }
        return $activeAlerts;
    }
    
    hidden static [PSObject] GetASCTasks([PSObject] $taskObjects) 
    {
        $activeTasks =@()

        if($null -ne $taskObjects -and ($taskObjects | Measure-Object).Count -gt 0)
        {                
            $taskObjects | ForEach-Object { 
                if([Helpers]::CheckMember($_, "Id")){
                $out = "" | Select-Object Name, State, ResourceId, Id
                Set-Variable -Name Name -Value $_.properties.securityTaskParameters.name
                Set-Variable -Name State -Value $_.properties.state     
                Set-Variable -Name ResourceId -Value $_.properties.securityTaskParameters.resourceId

                $out.Name = $Name
                $out.State = $State
                $out.ResourceId = $ResourceId
                $out.Id = $_.Id
                $activeTasks += $out
                }                
            }
        }
        return $activeTasks
    }
}