Functions/SSL/Register-WebCertificate.ps1
Function Register-WebCertificate { [cmdletbinding()] Param ( # URL to Certificate [Parameter(Mandatory=$true)] [string] $URI ) Process { # Get Certificate from Endpoint $Request = [Net.HttpWebRequest]::Create($URI) $Request.Method = "OPTIONS" $Certificate = $Request.ServicePoint.Certificate # Check for presence of Trusted Certificate if ($Certificate) { $CertificateStoreOwner = "LocalMachine" $CertificateStore = New-Object System.Security.Cryptography.X509Certificates.X509Store([System.Security.Cryptography.X509Certificates.StoreName]::Root,$CertificateStoreOwner) $CertificateStore.Open("ReadWrite") if (!($CertificateStore.Certificates.Subject -contains $Certificate.Subject)) { $CertificateStore.Add($Certificate) $FullCert = $CertificateStore.Certificates | where subject -eq $Certificate.Subject if($fullcert){Write-Host "Added $($FullCert.DnsNameList.Unicode) cert to Trusted Cert Store" -ForegroundColor Cyan} } $CertificateStore.Close() } } } |