0

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
    }
  }
}
4
  • How can i get it done for multiple servers, please help me
    – chandu
    Commented Feb 11, 2020 at 14:39
  • Is there an error? Can you just run this on another server? Do you mean you want to run this remotely on another machine from a single machine? Please clarify
    – Narzard
    Commented Feb 11, 2020 at 14:47
  • From a single machine i need to run this
    – chandu
    Commented Feb 11, 2020 at 16:55
  • 1
    should be able to use invoke command like this Invoke-Command -FilePath "c:\temp\getSSLCert.ps1" -ComputerName server1,server2,server3
    – Narzard
    Commented Feb 11, 2020 at 16:58

0

You must log in to answer this question.

Browse other questions tagged .