I have written the below code to export only the one server's SSL certificate details related to the IIS sites, but I want the script to run for multiple servers. How do I fix this issue?
Import-Module -Name WebAdministration
#Number of days to look for expiring certificates
$threshold = 300
#Set deadline date
$deadline = (Get-Date).AddDays($threshold)
Get-ChildItem -Path IIS:SSLBindings | ForEach-Object -Process
{
if ($_.Sites)
{
$certificate = Get-ChildItem -Path CERT:LocalMachine/My |
Where-Object -Property Thumbprint -EQ -Value $_.Thumbprint
[PsCustomObject]@{
ServerName = $env:COMPUTERNAME
Sites = $_.Sites.Value
CertificateIssuer = $certificate.Issuer
CertificateSubject = $certificate.Subject
CertificateDnsNameList = $certificate.DnsNameList
CertificateNotBefore = $certificate.NotBefore
CertificateNotAfter = $certificate.NotAfter
#CertificateExpiryInDays = New-TimeSpan -Start (Get-Date) -End $PSitem.NotAfter.Days
}
}
}
Invoke-Command -FilePath "c:\temp\getSSLCert.ps1" -ComputerName server1,server2,server3