Created
October 14, 2018 02:57
-
-
Save realslacker/043d9c70a3a806a015b937047446c949 to your computer and use it in GitHub Desktop.
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
<# | |
.SYNOPSIS | |
Signs a PS1 script with the local users code signing certificate. | |
.DESCRIPTION | |
Takes a PS1 file as an argument and signs with the local user's code signing certificate. | |
Optionally allows specification of a timestamp server. | |
.PARAMETER Path | |
A PS1 file to sign. Accepts pipeline input. | |
.PARAMETER TimestampServer | |
An optional parameter specifying a timestamp server. The default is 'http://timestamp.comodoca.com/authenticode'. | |
.OUTPUTS | |
A boolean, indicating whether the script was signed. | |
#> | |
Function Add-SignatureToScript { | |
[CmdletBinding()] | |
param( | |
[parameter(Mandatory=$true, Position=1, ValueFromPipeline=$True)] | |
[ValidateScript({ | |
if ( [IO.Path]::GetExtension( $_ ) -notmatch '.psm?1' ) { | |
throw "Path must point to an PS1 file." | |
} | |
$true | |
})] | |
[ValidateScript({ | |
if ( -not ( Test-Path $_ -PathType Leaf -ErrorAction SilentlyContinue ) ) { | |
throw "[$_] is not a file." | |
} | |
$true | |
})] | |
[ValidateScript({ | |
if ( -not ( Test-Path $_ -ErrorAction SilentlyContinue ) ) { | |
throw "[$_] does not exist." | |
} | |
$true | |
})] | |
[System.IO.FileInfo[]] | |
$Path, | |
[parameter( Mandatory=$false )] | |
[ValidateNotNullOrEmpty()] | |
[string] | |
$TimestampServer="http://timestamp.comodoca.com/authenticode" | |
) | |
process { | |
foreach ( $PathItem in $Path ) { | |
$Options = @{ | |
FilePath = $PathItem | |
Certificate = ( Get-ChildItem -Path Cert:\CurrentUser\My -CodeSigningCert ) | |
TimestampServer = $TimestampServer | |
} | |
Set-AuthenticodeSignature @Options | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment