-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-RemoteSSLCertificateDetails.ps1
46 lines (41 loc) · 1.3 KB
/
Get-RemoteSSLCertificateDetails.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
Function Get-RemoteSSLCertificateDetails
{
param($url)
Write-Log "Attempting connection to $url"
$request = $null
$request = [Net.HttpWebRequest]::Create($url)
$request.Timeout = 1200
try
{
$request.GetResponse() | Out-Null
}
catch
{
Write-Log "Error connecting to URL $url`: $_"
}
$cert = $null
$cert = $request.ServicePoint.Certificate
if($cert)
{
$hash = @{
result = "Success"
ExpirationDate = [datetime]$cert.GetExpirationDateString()
ExpiresIn = $(([DateTime]$cert.GetExpirationDateString() - $(Get-Date)).Days)
Name = $cert.GetName()
PublicKeyString = $cert.GetPublicKeyString()
SerialNumber = $cert.GetSerialNumberString()
Thumbprint = $cert.GetCertHashString()
EffectiveDate = $cert.GetEffectiveDateString()
Issuer = $cert.GetIssuerName()
}
#create a new powershell object out of the data so that we get all of the PS Object goodness
$Certificate = New-Object PSObject -Property $hash
return $Certificate
}
else
{
$return = New-Object PSObject
Add-Member -InputObject $return -MemberType NoteProperty -Name result -Value "fail"
return $return
}
}