PowerShell with WiX - 遍历证书存储并根据指纹删除证书
PowerShell with WiX - Loop through certificate store and remove cert based on thumbprint
我有一个简单的 PowerShell 脚本 运行 通过 WiX 安装程序。如您所见,它从 PFX 文件中获取指纹,然后循环遍历证书存储,如果找到它,就会将其删除。
$ConfirmPreference = 'None'
# server certificate path
$serverCertFilePath = "$dataTransferCertificatePath\server.pfx"
# get thumbprint from server cert info
$serverCertInfo = Get-PfxCertificate -FilePath $serverCertFilePath
$serverThumbprint = $serverCertInfo.Thumbprint
Get-ChildItem -Path Cert:\*$serverThumbprint -Recurse | Remove-Item -Force
我已经尝试 $ConfirmPreference = 'None'
和 Remove-Item
与 -Force
当我 运行 来自提升的 PowerShell 的以上两行时 它有效!
之后我 运行 使用 WiX 安装程序的相同脚本:
powershell.exe -NoLogo -NonInteractive –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"
然后我得到以下信息:
The operation is on user root store and UI is not allowed.
WiX 自定义操作调用如下:
<CustomAction Id="CA_RemoveCertificate_set"
Property="CA_RemoveCertificate"
Execute="immediate"
HideTarget="yes"
Value='"!(wix.PowerShell)" -NoLogo -NonInteractive –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"' />
<CustomAction Id="CA_RemoveCertificate"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="check"
Impersonate="yes" />
如有任何帮助,我们将不胜感激。
您可以尝试用 Start-Process -Verb RunAs powershell.exe
打开一个 运行-as-admin window
看起来如果你可以 运行 使用 sudo 它将执行。
为了应用修复程序,我在 WiX 自定义操作中调用 PowerShell 脚本时删除了 -NoLogo -NonInteractive:
对于 CA_RemoveCertificate_set 自定义操作值将为 "!(wix.PowerShell)" –ExecutionPolicy Unrestricted -File "Remove-Certificate .ps1"
<CustomAction Id="CA_RemoveCertificate_set"
Property="CA_RemoveCertificate"
Execute="immediate"
HideTarget="yes"
Value='"!(wix.PowerShell)" –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"' />
<CustomAction Id="CA_RemoveCertificate"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="check"
Impersonate="yes" />
我有一个简单的 PowerShell 脚本 运行 通过 WiX 安装程序。如您所见,它从 PFX 文件中获取指纹,然后循环遍历证书存储,如果找到它,就会将其删除。
$ConfirmPreference = 'None'
# server certificate path
$serverCertFilePath = "$dataTransferCertificatePath\server.pfx"
# get thumbprint from server cert info
$serverCertInfo = Get-PfxCertificate -FilePath $serverCertFilePath
$serverThumbprint = $serverCertInfo.Thumbprint
Get-ChildItem -Path Cert:\*$serverThumbprint -Recurse | Remove-Item -Force
我已经尝试 $ConfirmPreference = 'None'
和 Remove-Item
与 -Force
当我 运行 来自提升的 PowerShell 的以上两行时 它有效!
之后我 运行 使用 WiX 安装程序的相同脚本:
powershell.exe -NoLogo -NonInteractive –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"
然后我得到以下信息:
The operation is on user root store and UI is not allowed.
WiX 自定义操作调用如下:
<CustomAction Id="CA_RemoveCertificate_set"
Property="CA_RemoveCertificate"
Execute="immediate"
HideTarget="yes"
Value='"!(wix.PowerShell)" -NoLogo -NonInteractive –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"' />
<CustomAction Id="CA_RemoveCertificate"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="check"
Impersonate="yes" />
如有任何帮助,我们将不胜感激。
您可以尝试用 Start-Process -Verb RunAs powershell.exe
看起来如果你可以 运行 使用 sudo 它将执行。
为了应用修复程序,我在 WiX 自定义操作中调用 PowerShell 脚本时删除了 -NoLogo -NonInteractive:
对于 CA_RemoveCertificate_set 自定义操作值将为 "!(wix.PowerShell)" –ExecutionPolicy Unrestricted -File "Remove-Certificate .ps1"
<CustomAction Id="CA_RemoveCertificate_set"
Property="CA_RemoveCertificate"
Execute="immediate"
HideTarget="yes"
Value='"!(wix.PowerShell)" –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"' />
<CustomAction Id="CA_RemoveCertificate"
BinaryKey="WixCA"
DllEntry="CAQuietExec64"
Execute="deferred"
Return="check"
Impersonate="yes" />