Sign custom PowerShell scripts for Snow Inventory Agent
In Snow Inventory Agent for Windows 7.0 and later, PowerShell scripts that require medium-integrity execution must have a valid Authenticode signature. The signature is validated on the computer where the scan is performed.
Support for encrypted PowerShell scripts and .snow-ps1 files ended with this change.
Digital signatures help verify the source and integrity of a script by confirming that it comes from a trusted source and has not been modified after it was signed.
Configure the script for medium-integrity execution
To indicate that a script requires medium-integrity execution, add the following line to the script:
#MediumIntegrityLevel
Obtain a code-signing certificate
To sign the script, use a Code Signing certificate that supports Microsoft Authenticode.
You can obtain a code-signing certificate from a trusted certificate provider. If your organization operates its own Certificate Authority (CA) as part of its PKI, you can also create the certificate there.
Sign the script
PowerShell scripts can be signed using tools such as:
- PowerShell
Set-AuthenticodeSignature - Microsoft
signtool.exe - AzureSignTool
Validate the signed script
Use the PowerShell Get-AuthenticodeSignature cmdlet to validate the signed script.
Create a self-signed certificate for development
The certificate used to sign a script must have a valid certificate chain when the Snow Inventory Agent runs. The certificate chain must end with a trusted root Certificate Authority (CA).
For development purposes, you can create and manage a self-signed certificate using PowerShell, certmgr.exe, or the Certificates MMC snap-in. The following example uses PowerShell:
# 1. Create a selfsigned cert: New-SelfSignedCertificate -Type CodeSigningCert -Subject "My Certificate for Development" -CertStoreLocation Cert:\CurrentUser\My # 2. Make it trustworthy: # 2a. Export the certificate without the private key: Export-Certificate -Cert (Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert)[0] -FilePath code_signing.crt # The [0] will make this work for cases when you have more than one certificate. # Make the index match the certificate you want to use, or filter by thumbprint or issuer. # 2b. Import it as Trusted Publisher Import-Certificate -FilePath .\code_signing.crt -Cert Cert:\CurrentUser\TrustedPublisher # 2c. Import it as a Root certificate authority. Import-Certificate -FilePath .\code_signing.crt -Cert Cert:\CurrentUser\Root # 3. Sign the script (assuming here it's named script.ps1, fix the path accordingly). Set-AuthenticodeSignature .\script.ps1 -Certificate (Get-ChildItem Cert:\CurrentUser\My -CodeSigningCert)[0] -HashAlgorithm SHA256 # The [0] will make this work for cases when you have more than one certificate. # Make the index match the certificate you want to use, or filter by thumbprint or issuer. # Once you have set up the key, you can sign other scripts with it.
Important: This self-signed certificate example is intended for development purposes. The signing certificate must be trusted by the computer where the Snow Inventory Agent validates the script.
Frequently asked questions
Does every PowerShell script need to be signed?
No. Only scripts that require the elevated security context of medium integrity need to be signed.
Scripts that require only low integrity do not need to be signed, although they can be.
Why was PowerShell script encryption removed?
It is recommended to protect intellectual property through licensing.
Encryption makes it difficult for third parties to validate what a script does and determine whether they can safely use it in their infrastructure. It also makes it difficult to validate the authenticity of a script, whether it has been modified, and where it originated.
Do certificates need to be distributed to each computer?
If the certificate used to sign the script has a trust chain to a root Certificate Authority that is already trusted by the computer, no additional certificate needs to be installed.
If you use a self-signed certificate, the root CA must be installed on each computer so that the computer can validate the signature.