Skip to content

Instantly share code, notes, and snippets.

@dsolodow
Last active April 21, 2022 17:28
Show Gist options
  • Save dsolodow/b364a223d4b7a855eefa8ef96d691cae to your computer and use it in GitHub Desktop.
Save dsolodow/b364a223d4b7a855eefa8ef96d691cae to your computer and use it in GitHub Desktop.
PowerShell signature function
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