Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## TEST-CERTIFICATE
- ##
- ## Script to check the status of a certificate
- ##
- ## v1.0
- ## Nial Francis 16/05/2019
- [CmdletBinding()]
- param(
- [Parameter(Mandatory=$True)][string]$CertPath
- )
- function Test-Certificate ($CertPath) {
- $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
- $chain = New-Object System.Security.Cryptography.X509Certificates.X509Chain
- $cert.Import($CertPath)
- try {
- $status = $chain.Build($cert)
- } catch {
- throw "File is not a valid certificate"
- }
- if ($status) {
- Write-Host "The certificate is valid"
- } else {
- Write-Host "The certificate is invalid due to:"
- foreach ($item in $chain.ChainStatus) {
- $hash += @{ $item.Status = $item.StatusInformation }
- }
- ($hash | Format-Table -HideTableHeaders -Wrap | Out-String).Trim()
- }
- }
- Test-Certificate $CertPath
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement