OpsaC - Operating as PowerShell code
published: March 23, 2019 author: Tinu tags: PowerShell categories: System-Engineering
$Issuer = '*'
Get-ChildItem Cert:\LocalMachine -Recurse | Where-Object Issuer -match "CN=$Issuer"
$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
$Source = 'C:\temp\certstoimport'
$Target = 'Cert:\LocalMachine\Root'
foreach($item in (Get-ChildItem $Source -Filter '*.cer')){
Import-Certificate -FilePath $item.FullName -CertStoreLocation $Target
}
$Issuer = '*'
$certs = Get-ChildItem Cert:\LocalMachine -Recurse | Where-Object Issuer -match "CN=$Issuer"
foreach($item in $certs){
Remove-Item $item
}
Certificate Provider on Microsoft Docs.