By using the below code, I can get the number of certificates which are expiring in the current server. How can I modify this code to get the name of the certificates which are expiring in 90 days on a multiple remote servers?
# Define an array to store certificate paths
$certPaths = @(
"Cert:LocalMachineMy"
)
# Initialize a counter for certificates expiring soon
$certificatesExpiringSoonCount = 0
# Calculate the date 90 days from now
$expiryThreshold = (Get-Date).AddDays(90)
# Loop through each certificate path
foreach ($certPath in $certPaths) {
# Get all certificates in the current store
$certificates = Get-ChildItem -Path $certPath
#$certificates
foreach ($cert in $certificates) {
# Check if the certificate expiry date is in the future and within the next 90 days
if ($cert.NotAfter -gt (Get-Date) -and $cert.NotAfter -lt $expiryThreshold) {
# Increment the counter for certificates expiring soon
$certificatesExpiringSoonCount++
}
}
}
# Output the total number of certificates expiring soon
Write-Output "Total number of certificates expiring in 90 days: $certificatesExpiringSoonCount"