Skip to content
INSIGHTS & GUIDES · NETCLOUD24

Signing a PowerShell release with a trusted code-signing identity

Sign a reviewed PowerShell release with an explicitly authorised key and timestamp service, verify provenance and trust on target servers, and preserve release, renewal and compromise handling without treating signatures as a safety guarantee.

Read the article ↓
Editorial illustration: How to Sign a PowerShell Script with a Code-Signing Certificate

Platform: Windows Server 2019, 2022 and 2025, with the version and hosting restrictions described below.

Define what the signature should establish

An Authenticode signature associates script content with a signing identity and detects later modification. It does not prove that the script is safe, correct or authorised for every server. Review and version the code before signing, and protect the private key so an attacker cannot sign arbitrary replacements. The trust decision belongs to the deployment process as well as the certificate chain.

For managed Netcloud24 automation, the team prepares reviewed scripts and their distribution controls. Customers should not be expected to bypass execution policy or trust an unknown publisher to receive the service. This guide describes an authorised release operator signing an approved script with an existing code-signing certificate, then verifying it on representative targets.

Obtain a certificate for code signing rather than another purpose

Use an approved CA or signing service and a certificate with the Code Signing purpose. A web-server certificate is not an interchangeable signing credential. Define who may request, use, renew and revoke the certificate, and whether the key belongs in protected hardware or a restricted signing host. Avoid distributing the signing private key to every target server.

A self-signed certificate can support a deliberately controlled laboratory, but creating one does not make it trusted across production. Public or enterprise trust paths need their own approved distribution. Verify the intended publisher and chain on clients rather than adding every encountered certificate to Trusted Publishers automatically.

Keep the timestamp service and its allowed network path part of the design. A valid trusted timestamp can preserve the ability to evaluate a signature relative to signing time after the signer certificate expires, subject to validation policy. It does not make a revoked or compromised signing identity harmless or guarantee every verifier behaves identically.

Prepare the exact release artifact

Choose the script version, encoding and final content before signing. Editing line endings or generated sections afterwards changes the signed bytes and invalidates the signature. Build first, review, then sign the final artifact. Keep an unsigned source copy in version control and publish the signed release through the approved channel.

Check paths and permissions on the signing host. Ordinary users should not replace the release between review and signing. Avoid placing credentials in the script; a signature provides integrity, not confidentiality. Anyone able to read the file can still read embedded secrets.

$release = 'C:\ReleaseStaging\Build-Report.ps1'
Get-Item -LiteralPath $release | Select-Object FullName,Length,LastWriteTime
Get-FileHash -LiteralPath $release
Get-AuthenticodeSignature -FilePath $release

Record the version and pre-signing hash as useful release evidence. A hash alone does not establish publisher trust, and an existing signature should be inspected before deciding whether the file is the expected source artifact.

Select the authorised signing key explicitly

Inspect available code-signing certificates and select the exact approved thumbprint. Verify subject, issuer, validity, purpose and private-key availability. Do not choose whichever certificate expires last or happens to be first in the store. HSM-backed or remote signing has additional provider and authorisation steps that must be followed.

Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert |
  Select-Object Subject,Thumbprint,NotAfter,HasPrivateKey
$signingThumbprint = 'REPLACE_WITH_APPROVED_SIGNING_CERTIFICATE_THUMBPRINT'
$signingIdentity = Get-Item ('Cert:\CurrentUser\My\' + $signingThumbprint) -ErrorAction Stop
if (-not $signingIdentity.HasPrivateKey) { throw 'The approved signing key is unavailable.' }

The user-store example assumes the signing service’s approved identity. It is not a reason to import the key into a general administrator profile. Protect any export material and never attach a PFX and its password to an ordinary deployment ticket.

Sign with the reviewed timestamp endpoint

Use the approved timestamp URL supplied by the signing design. The placeholder below must be replaced by that actual service; it is not a request to trust an arbitrary timestamp server. SHA-256 is selected for this example, subject to current compatibility and policy.

$timestampService = 'REPLACE_WITH_APPROVED_TIMESTAMP_SERVICE_URL'
$signedResult = Set-AuthenticodeSignature -FilePath $release `
  -Certificate $signingIdentity -HashAlgorithm SHA256 `
  -TimestampServer $timestampService
$signedResult | Select-Object Path,Status,StatusMessage
Get-AuthenticodeSignature -FilePath $release |
  Format-List Status,StatusMessage,SignerCertificate,TimeStamperCertificate

Inspect both signing and timestamp results. A command that adds a signature block but reports a trust or timestamp error has not necessarily met the release requirement. Preserve the error and check endpoint reachability, provider access and trust rather than removing the timestamp requirement silently.

Verify on the intended execution platform

Transfer the signed artifact through the controlled deployment path without rewriting it. On a representative target, verify Authenticode status, expected signer and chain, timestamp and file integrity. A signature valid only on the signing host can fail elsewhere because trust roots, publisher policy or revocation access differ.

Get-AuthenticodeSignature -FilePath 'C:\ProgramData\ManagedJobs\Scripts\Build-Report.ps1' |
  Select-Object Status,StatusMessage,SignerCertificate,TimeStamperCertificate
Get-ExecutionPolicy -List

Execution policy is an administrative safeguard, not a security boundary against a determined actor with execution rights. Do not describe signing or AllSigned as a complete application-control solution. Use the organisation’s broader application control, least privilege and deployment protections where required.

Test the script’s actual job under its intended identity. A valid signature does not grant missing network or file permissions and does not make an interactive-only script suitable for a scheduled task.

Diagnose invalid signatures without approving unknown code

HashMismatch normally points to content modification after signing or transfer rewriting. NotTrusted can involve chain or publisher trust, while other failures need their precise status and revocation context inspected. Compare the expected release and signer before allowing execution.

Do not bypass policy or trust an unexpected publisher just because a deployment deadline is close. Rebuild and sign the correct final artifact through the release process. If the signing key is suspected compromised, stop new use and follow certificate and release-response procedures; re-signing malicious content with the same exposed key is not recovery.

Avoid automatically trusting a certificate extracted from any downloaded script. Trust distribution needs an independent approved basis, otherwise an attacker can provide both code and the identity used to justify it.

Maintain signatures through the release lifecycle

Every content change needs a new reviewed signature. Retain the source version, signed artifact, signer, timestamp and deployment evidence. Plan certificate renewal and how clients receive updated trust. Preserve valid old release evidence according to retention rather than deleting it when a new key is issued.

Rollback deploys a known approved earlier artifact and validates its signature and application compatibility; it does not simply remove the signature block from a failing file. The managed outcome is traceable code provenance supported by review and protected delivery, with clear limits on what cryptographic signing alone can establish.

Further reading


Was this answer helpful?

« Back
Contact

Write to us

Do you have questions about our services or need a quote? Write to us and we will respond as soon as possible.

Contact form

Fields marked * are required.