Created
January 12, 2020 19:52
-
-
Save SQLDBAWithABeard/67a2b6af464f7896debbb17649524a3b to your computer and use it in GitHub Desktop.
cert code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = 'Stop' | |
# read in the certificate from a pre-existing PFX file | |
# I have checked this with IISResetMe and this does not go in the store only memory | |
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::new("$(Agent.WorkFolder)\_temp\dbatools-code-signing-cert.pfx","$(CertPassword)") | |
try { | |
Write-Output "Signing Files" | |
# find all scripts in your module... | |
Get-ChildItem -Filter *.ps1 -Include *.ps1 -Recurse -ErrorAction SilentlyContinue | | |
# ...that do not have a signature yet... | |
Where-Object { | |
($_ | Get-AuthenticodeSignature).Status -eq 'NotSigned' | |
} | | |
# and apply one | |
# (note that we added -WhatIf so no signing occurs. Remove this only if you | |
# really want to add digital signatures!) | |
Set-AuthenticodeSignature -Certificate $cert | |
Write-Output "Signed Files" | |
} | |
catch { | |
$_ | Format-List -Force | |
Write-Error "Failed to sign scripts" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment