I have a simple PowerShell script that runs via a WiX installer. As you can see, it takes a thumbprint from PFX file an loops through the cert store and removes it if it finds it.
$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
I have tried $ConfirmPreference = 'None'
and Remove-Item
with -Force
When I run the above two lines from an elevated PowerShell it works!
After that I run the same script using WiX installer:
powershell.exe -NoLogo -NonInteractive –ExecutionPolicy Unrestricted -File "Remove-Certificate.ps1"
Then I get the following:
The operation is on user root store and UI is not allowed.
WiX Custom Action calling as follow:
<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" />
Any help would be appreciated.
To apply a fix I had removed -NoLogo -NonInteractive while calling PowerShell script in WiX Custom Action:
For CA_RemoveCertificate_set custom action value will be "!(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" />