Last active
April 21, 2022 17:28
-
-
Save dsolodow/b364a223d4b7a855eefa8ef96d691cae to your computer and use it in GitHub Desktop.
PowerShell signature function
This file contains 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
function Set-Signature { | |
[CmdletBinding()] | |
[Alias('sig')] | |
param( | |
[Parameter( | |
Mandatory, | |
Position = 0, | |
ValueFromPipeline, | |
ValueFromPipelineByPropertyName | |
)] | |
[ValidateScript({Test-Path -Path $PSItem})] | |
[ValidateNotNullOrEmpty()] | |
[string[]]$FilePath | |
) | |
BEGIN { | |
$Certificate = Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert | | |
Where-Object -Property NotAfter -GT (Get-Date) | | |
Sort-Object -Property NotAfter -Descending | | |
Select-Object -First 1 | |
} | |
PROCESS { | |
foreach ($Path in $FilePath) { | |
$Params = @{ | |
Certificate = $Certificate | |
TimestampServer = 'http://timestamp.digicert.com' | |
HashAlgorithm = 'SHA256' | |
FilePath = $Path | |
Verbose = $True | |
} | |
Set-AuthenticodeSignature @Params | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment