电源外壳。循环遍历证书存储并根据指纹删除证书

Xyz*_*Xyz 5 powershell certificate

我有一个通过 GPO 启动脚本运行的简单 powershell 脚本。如您所见,它会在证书存储中循环获取指纹,并在找到它时将其删除。

#thumbprint of certificate to remove
$thumb = "abcdef444444857694df5e45b68851868"

#loop through all the certs stores looking for $thumb and remove if found
get-childitem Cert:/ -recurse | where-object {$_.thumbprint -contains "$thumb"} | remove-item

Run Code Online (Sandbox Code Playgroud)

当我从提升的 powershell 提示符运行上面两行时,它起作用了

如果我重新启动计算机并让 GPO 执行此操作,或者如果我从提升的 powershell 运行,则会出现以下提示:

powershell.exe -Noninteractive -ExecutionPolicy Bypass -Noprofile -file "\\mydomain.corp\SysVol\mydomain.corp\Policies\{7086C68E-D509-9169-A02B-56579826C234}\Machine\Scripts\Startup\removecerts.ps1"
Run Code Online (Sandbox Code Playgroud)

然后我得到以下信息:

remove-item :该操作针对用户根存储,并且不允许 UI。

任何帮助,将不胜感激。

Mat*_*sen 1

我怀疑它会提示确认,而在无头运行时则无法提示确认。

添加-Force参数应该覆盖确认提示:

... | Remove-Item -Force
Run Code Online (Sandbox Code Playgroud)

或者,在尝试删除证书之前将$ConfirmPreference变量设置为 以避免出现提示:None

$ConfirmPreference = 'None'
<# rest of script goes here #>
Run Code Online (Sandbox Code Playgroud)