r/PowerShell • u/QuickBooker30932 • Nov 27 '25
Trouble with self-signed security certificate
I'm having trouble with my first self-signed certificate. I followed these steps to create it:
# Create a certificate$selfsigncert = New-SelfSignedCertificate -Subject "CN=PowerShell Code Signing" -KeyAlgorithm RSA -KeyLength 2048 -Type CodeSigningCert -CertStoreLocation Cert:\LocalMachine\My
# Move the root cert into Trusted Root CAsMove-Item "Cert:\LocalMachine\My\$($selfsigncert.Thumbprint)" Cert:\LocalMachine\Root
# Obtain a reference to the code signing cert in Trusted Root$selfsignrootcert = "Cert:\LocalMachine\Root\$($selfsigncert.Thumbprint)"
But signing the script doesn't seem to work. I entered this:
Set-AuthenticodeSignature .\ScriptName.ps1 $selfsignrootcert
And I get this error:
Set-AuthenticodeSignature: Cannot bind parameter 'Certificate'. Cannot convert value "Cert:\LocalMachine\Root\[omitted]" to type "System.Security.Cryptography.X509Certificates.X509Certificate2". Error: "The filename, directory name, or volume label syntax is incorrect."
I've tried using the complete script path in quotes but get the same error.
View all comments
Show parent comment
1
u/Certain-Community438 Nov 27 '25
That should probably read
"...so that you can sign the private key"
An irritating facet of working with keypairs on Windows is how often the private key's existence is either ignored or masked by standard processes - like
New-SelfSignedCertificate- causing some admins to conflate the key & the cert... leading to potential confusion when they need to consider both