-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathGet-SslLabsScore.ps1
56 lines (50 loc) · 2.38 KB
/
Get-SslLabsScore.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
function Get-SslLabsScore{
[CmdletBinding()]
Param(
[Parameter(Mandatory = $true,
ValueFromPipelineByPropertyName = $true,
ValueFromPipeline = $true,
Position = 0)]
[String[]]$UrlList
)
Begin{
[int]$i = 0
}
Process{
Foreach ($Url in $UrlList) {
try {
$i++
Write-Progress -Activity "Checking URI" -Status "$Url - $i/$(@($UrlList).count) $($i/$(@($UrlList).count)*100 -as [int])%" -PercentComplete ($i/$(@($UrlList).count)*100 -as [int])
#API Doc https://github.com/ssllabs/ssllabs-scan/blob/master/ssllabs-api-docs-v3.md
$API = "https://api.ssllabs.com/api/v2/analyze?host=$url&all=on&maxAge=24&"
do{
$JsonData = Invoke-WebRequest -Uri $API -ErrorAction SilentlyContinue | ConvertFrom-Json
Write-Verbose -Message "$($Url): Status is $($JsonData.status), sleeping for 20 seconds"
Start-Sleep -seconds 20
}
while ((-Not($JsonData.status -eq "Ready") ))
New-Object -TypeName PSObject -Property @{
Host = $JsonData.Host
IPAddress = $JsonData.endpoints.ipAddress
Grade = $JsonData.endpoints.grade
StatusMessage = $JsonData.endpoints.statusMessage
DurationSeconds = $JsonData.endpoints.duration/1000 -as [int]
#Key
KeyStrength = $JsonData.endpoints.details.key.size
#Cert
CommonName = $JsonData.endpoints.details.cert | Select-Object -ExpandProperty commonNames
SAN = ($JsonData.endpoints.details.cert | Select-Object -ExpandProperty altNames) -join ','
Issuer = $JsonData.endpoints.details.cert.issuerLabel
notBefore = ([DateTime]'1/1/1970').AddMilliseconds($JsonData.endpoints.details.cert.notBefore)
notAfter = ([DateTime]'1/1/1970').AddMilliseconds($JsonData.endpoints.details.cert.notAfter)
sigAlg = $JsonData.endpoints.details.cert.sigAlg
}
}
catch {
Write-Warning -Message "$Url failed: $_ !"
}
}
}
End{
}
}