Tinus EngOps Wiki

Logo

OpsaC - Operating as PowerShell code

Links

Home

PowerShell Blog

PowerShell Index

PowerShell Search

Additional Websites

View my GitHub Profile

View my GitHub Gists

View Tinus IT Wiki

View my Photo Website

Certificates

published: March 23, 2019 author: Tinu tags: PowerShell categories: System-Engineering


Table of Contents

List certificates

$Issuer = '*'
Get-ChildItem Cert:\LocalMachine -Recurse | Where-Object Issuer -match "CN=$Issuer"

List all expired certificates

$Issuer = '*'
$certs = Get-ChildItem Cert:\LocalMachine -Recurse | Where-Object Issuer -match "CN=$Issuer"
$ret = foreach($item in $certs){
   if($item.NotAfter.Date -le (Get-Date)){
      [PSCustomObject]@{
         Issuer     = $item.Issuer
         ValidFrom  = $item.NotBefore.Date
         ExpiresOn  = $item.NotAfter.Date
         KeyLength  = $item.PublicKey.Key.KeySize
         Thumbprint = $item.Thumbprint
      }
   }
}
$ret | Format-List

Import certificates

$Source = 'C:\temp\certstoimport'
$Target = 'Cert:\LocalMachine\Root'
foreach($item in (Get-ChildItem $Source -Filter '*.cer')){
   Import-Certificate -FilePath $item.FullName -CertStoreLocation $Target
}

Remove certificates

$Issuer = '*'
$certs  = Get-ChildItem Cert:\LocalMachine -Recurse | Where-Object Issuer -match "CN=$Issuer"
foreach($item in $certs){
   Remove-Item $item
}

See also

Certificate Provider on Microsoft Docs.


← Previous Post [ Top ] Copyright © 2024 by tinuwalther [ Blog ] Next Post →