Skip to content

Instantly share code, notes, and snippets.

@fullenw1
Last active April 13, 2020 19:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fullenw1/dd7f25452914f97b8efcb1c22ebaa515 to your computer and use it in GitHub Desktop.
Save fullenw1/dd7f25452914f97b8efcb1c22ebaa515 to your computer and use it in GitHub Desktop.
Code signature function #PKI #Certificates #Security
function Set-Signature {
[CmdletBinding()]
[Alias('sig')]
param(
[Parameter(
Mandatory,
Position = 0,
ValueFromPipeline,
ValueFromPipelineByPropertyName
)]
[ValidateScript( { Test-Path -Path $_ })]
[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) {
$TimeStampServer = @(
'http://timestamp.verisign.com/scripts/timstamp.dll'
'http://timestamp.globalsign.com/scripts/timstamp.dll'
'http://timestamp.comodoca.com/authenticode'
) | Get-Random
$Params = @{
Certificate = $Certificate
TimestampServer = $TimeStampServer
HashAlgorithm = 'SHA256'
FilePath = $Path
}
Set-AuthenticodeSignature @Params
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment