-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdd-TenableScan.ps1
More file actions
48 lines (43 loc) · 1.51 KB
/
Add-TenableScan.ps1
File metadata and controls
48 lines (43 loc) · 1.51 KB
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
function New-TenableScan {
$Date = Get-Date -UFormat "%b %d %Y_%H:%M"
$Name = ([System.Net.Dns]::GetHostByName(($env:computerName))).Hostname
$ReportName = "$($Name) - $($Date)"
$ManagedCredsUUID = "<Managed Credentials UUID>"
$FolderID = $FolderID
$Scanner = $ScannerID
$ScanURI = "https://cloud.tenable.com/scans"
$AccessKey = $AccessKey
$SecretKey = $SecretKey
$Headers = @{ }
$Headers.Add("accept", "application/json")
$Headers.Add("X-ApiKeys", "accessKey=$AccessKey;secretKey=$Secretkey")
$TemplateUUID = $TemplateUUID
$ScanSettings = [ordered]@{
uuid = $TemplateUUID
settings = @{
name = $ReportName
folder_id = $FolderID
scanner_id = $Scanner
text_targets = $Name
}
credentials = @{
add = @{
Host = @{
Windows = @(
@{
id = $ManagedCredsUUID
}
)
}
}
}
}
$JSON = $ScanSettings | ConvertTo-Json -Depth 5
$Response = Invoke-RestMethod -Uri $ScanURI -Method Post -Headers $Headers -ContentType 'application/json' -Body $JSON
return $Response
}
function Start-TenableScan {
$CreateResponse = New-TenableScan
$ScanUUID = "https://cloud.tenable.com/scans/$($CreationResponse.scan.uuid)/launch"
$StartScanResponse = Invoke-RestMethod -Uri $ScanUUID -Method POST -Headers $headers
}