This article explains how we can get an SSL certificate on remote windows computers or a server operating system using Powershell script, here are the simple steps one can follow and achieve the same.
Windows administrators deal with many servers and desktop machines every day as part of their work and they work on SSL certificates, they query, install and remove, certificates. This article explains how to query a specific certificate on many remote computers, here is the simple code that pulls certificate information.
We need to create a text file for remote computers list that we are going to query the certificate information, here I have created a text file named as allservers.txt and saved it in location C\temp\allservers.txt
Powershell Script Code
$Allservers = Get-Content "C:\temp\Allservers.txt"
$output = @()
$CertificateName = "GlobalSign"
$ErrorActionPreference = 'SilentlyContinue'
foreach($Server in $Allservers)
{
Write-Host Processing $Server -ForegroundColor yellow
Try
{
$machinename = ([System.Net.Dns]::GetHostByName("$Server")).hostname
$certificates = Invoke-Command $Server -ScriptBlock{ Get-ChildItem Cert:\LocalMachine\TrustedPublisher}
}
Catch
{
$_.Exception.Message
Continue
}
If($machinename -and $certificates)
{
Foreach($Cert in $certificates)
{
$Object = New-Object PSObject
$Object | Add-Member Noteproperty "Server name" -Value $machinename
$Object | Add-Member Noteproperty "Certificate name" -Value $cert.dnsnamelist.punycode
$Object | Add-Member Noteproperty "Certificate issuer" -Value $cert.issuer
$Object | Add-Member Noteproperty "Certificate expiration date" -Value $cert.notafter
$Object | Add-Member Noteproperty "Certificate thumbprint" -Value $cert.thumbprint
$output += $Object
}
}
Else
{
Write-Warning "Unable to Find, please check the server name or list"
}
}
$output | Where-Object {$_ -like "*$CertificateName*"} | Export-Csv -Path C:\Raj\certinfo.csv -Force -NoTypeInformation
In the above script, I used the certificate location as LocalMachine\TrustedPublisher and I’m searching for Globalsign certificate information. One has to change these details to search for your required certificate details.
Thank you for reading this article, please comment for any queries.
Leave a Reply Cancel reply