如果满足条件,则会按预期删除证书,但文本“正在删除证书”未显示。
请告知
$pc = '.'
$cert_store = 'My'
write "The is the cert store we are working with : $cert_store"
$store = New-Object system.security.cryptography.X509Certificates.X509Store ("My","LocalMachine") #LocalMachine could also be LocalUser
$store.Open('ReadWrite')
write "opening the store for editing"
## Find all certs that have an Issuer of old CA
$certs = $store.Certificates | Where { $_.Issuer -eq 'CN=DomainRootCA, DC=Corporate, DC=Local' }
if ($certs -ne $null)
{
## Remove all the certs it finds
$certs | foreach { $store.Remove($_) | write "The cert is being removed" }
}
答案 0 :(得分:2)
我相信这是因为删除没有任何输出。如果将管道(|)更改为分号(;),则可以正常工作。
$pc = '.'
$cert_store = 'My'
write "The is the cert store we are working with : $cert_store"
$store = New-Object system.security.cryptography.X509Certificates.X509Store ("My","LocalMachine") #LocalMachine could also be LocalUser
$store.Open('ReadWrite')
write "opening the store for editing"
## Find all certs that have an Issuer of old CA
$certs = $store.Certificates | Where { $_.Issuer -eq 'CN=DomainRootCA, DC=Corporate, DC=Local' }
if ($certs -ne $null)
{
## Remove all the certs it finds
$certs | foreach { $store.Remove($_) ; write "The cert is being removed" }
}