-
Notifications
You must be signed in to change notification settings - Fork 0
/
F5ExpiredCertsVips.ps1
79 lines (50 loc) · 2.66 KB
/
F5ExpiredCertsVips.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
$pass = ConvertTo-SecureString -string "PASSWORD" -AsPlainText -Force ##F5 Password
$f5Cred = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList "admin", $pass ### F5 USER
$F5_IP = '1.1.1.1' ## F5 IP
$path = "C:\temp\vs.csv" ## Path to save the CSV report
$expired_array = @()
$VS_array = @()
$unix_timestamp_now = [int][double]::Parse((Get-Date -UFormat %s))
try {
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@ }
catch {
pass
}
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
$sslProfilesClient = (Invoke-RestMethod -Method GET -Uri "https://$F5_IP/mgmt/tm/ltm/profile/client-ssl" -Credential $f5Cred).items
$virtualServers = Invoke-RESTMethod -Method GET -Uri "https://$F5_IP/mgmt/tm/ltm/virtual?expandSubcollections=true&`$select=name,partitioclsn,fullPath,profilesReference" -Credential $f5Cred
foreach($cert_profile in $sslProfilesClient){
$url = ($cert_profile.certreference.link).replace('localhost',$F5_IP)
$cert_file = Invoke-RestMethod -Method GET -Uri $url -Credential $f5Cred
if ($cert_file.expirationDate -lt $unix_timestamp_now){
$SSL_Object = New-Object PSObject
$SSL_Object | add-member Noteproperty CertProfile $cert_profile.name
$SSL_Object | add-member Noteproperty CertFile $cert_file.name
$SSL_Object | add-member Noteproperty fullPath $cert_profile.fullPath
$SSL_Object | add-member Noteproperty CertExpiry $cert_file.expirationString
$expired_array += $SSL_Object
}
}
foreach($virtualserver in $virtualservers.items){
foreach ($cert in $expired_array){
if($virtualserver.profilesReference.items.fullPath -eq $cert.fullPath -and $virtualserver.profilesReference.items.namereference.link -match 'client-ssl'){
$VS_Object = New-Object PSObject
$VS_Object | add-member Noteproperty CertProfile $cert.CertProfile
$VS_Object | add-member Noteproperty CertFile $cert.CertFile
$VS_Object | add-member Noteproperty VirtualServer $virtualserver.name
$VS_Object | add-member Noteproperty CertExpiry $cert.CertExpiry
$VS_array += $VS_Object
}
}
}
$VS_array | select CertProfile,CertFile,VirtualServer,CertExpiry | export-csv -Path $path