| 12
 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
 
 | function Invoke-SecurityScan {[CmdletBinding()]
 param(
 [Parameter(Mandatory=$true)]
 [string]$ResourceGroup,
 
 [ValidateSet('Critical','High','Medium')]
 [string]$SeverityLevel = 'High'
 )
 
 $securityReport = [PSCustomObject]@{
 Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
 ScannedResources = @()
 SecurityFindings = @()
 }
 
 
 $alerts = Get-AzSecurityAlert -ResourceGroupName $ResourceGroup |
 Where-Object { $_.Severity -eq $SeverityLevel }
 
 
 $alerts | ForEach-Object {
 $securityReport.ScannedResources += [PSCustomObject]@{
 ResourceID = $_.ResourceId
 AlertType = $_.AlertType
 CompromiseEntity = $_.CompromisedEntity
 }
 
 
 if($_.AlertType -eq 'UnusualResourceDeployment') {
 Start-AzResourceDelete -ResourceId $_.ResourceId -Force
 $securityReport.SecurityFindings += [PSCustomObject]@{
 Action = 'DeletedSuspiciousResource'
 ResourceID = $_.ResourceId
 Timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
 }
 }
 }
 
 
 $securityReport | ConvertTo-Json -Depth 3 |
 Out-File -FilePath "$env:TEMP/AzureSecReport_$(Get-Date -Format yyyyMMdd).json"
 return $securityReport
 }
 
 |