Advertisement
Guest User

Untitled

a guest
May 26th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1. ## TEST-CERTIFICATE
  2. ##
  3. ## Script to check the status of a certificate
  4. ##
  5. ## v1.0
  6. ## Nial Francis 16/05/2019
  7.  
  8. [CmdletBinding()]
  9. param(
  10. [Parameter(Mandatory=$True)][string]$CertPath
  11. )
  12.  
  13. function Test-Certificate ($CertPath) {
  14. $cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
  15. $chain = New-Object System.Security.Cryptography.X509Certificates.X509Chain
  16.  
  17. $cert.Import($CertPath)
  18. try {
  19. $status = $chain.Build($cert)
  20. } catch {
  21. throw "File is not a valid certificate"
  22. }
  23.  
  24. if ($status) {
  25. Write-Host "The certificate is valid"
  26. } else {
  27. Write-Host "The certificate is invalid due to:"
  28. foreach ($item in $chain.ChainStatus) {
  29. $hash += @{ $item.Status = $item.StatusInformation }
  30. }
  31. ($hash | Format-Table -HideTableHeaders -Wrap | Out-String).Trim()
  32. }
  33. }
  34.  
  35. Test-Certificate $CertPath
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement