I want to delete private key which is associated to a certificate in LocalMachine\Root using Powershell scripts. I need to first find this certificate from the store by using its friendly name since we don't have the thumbprint.
I used Remove-Item -DeleteKey
, but it deletes only the certificate from the LocalMachine\Root but the private key is still present in the Personal folder.
I could not find any straight forward answers after searching many forums. Any help is appreciated.
Powershell version - 5.1, OS - Windows 10
I tried the below code and it deletes only the certificate from Root and not the Private key.
$certFriendlyName = 'MyTestCertificate'
Set-Location Cert:\LocalMachine\Root
$cert = Get-ChildItem | Where-Object {$_.FriendlyName -match $certFriendlyName}
$cert
$cert | Remove-Item -DeleteKey
If i don't Set-Location, "-DeleteKey" switch is not working and throwing an error
A parameter cannot be found that matches parameter name 'DeleteKey'