I'm trying to do a script to remove a cert from workstations in the Computer Personal store that is expired and from a specific issuer,
This works fine to remove all expired certs from the store:
$Certs = Get-ChildItem "Cert:\LocalMachine\My" -Recurse
Foreach($Cert in $Certs) {
If($Cert.NotAfter -lt (Get-Date)) {
$Cert | Remove-Item
}
}
This is what I've tried to add the issuer but I can't get it to work:
$Certs = Get-ChildItem "Cert:\LocalMachine\My" -Recurse
Foreach($Cert in $Certs) {
If($Cert.NotAfter -lt (Get-Date) -and ($_.issuer -eq "Issuer Name") {
$Cert | Remove-Item
}
}
Additionally it would be cool to be able to also base the condition on if the Certificate was issued to the FQ host name of the client but this is less important.
Any help in the right direction is appreciated.