Code/Set-Signatures.ps1

#requires -version 4.0
###############################################################################
# WintellectPowerShell Module
# Copyright (c) 2014 - John Robbins/Wintellect
#
# Do whatever you want with this module, but please do give credit.
###############################################################################

# Always make sure all variables are defined and all best practices are
# followed.
Set-StrictMode -version Latest

function Set-Signatures
{
<#
.SYNOPSIS
Simple wrapper script for digitally signing files
.DESCRIPTION
Automatically grabs the first code signing certificate in CurrentUser\My and
uses the Comodo time stamp server so you just have to worry about the files.
.PARAMETER Files
The files to digitally sign. Any files that can be normally digitally
signed can be passed here.
.PARAMETER Certificate
Defaults to first code signing certificate in the cert:\CurrentUser\My
certificate storage that does not have Azure in the name.
.PARAMETER TimeStampServer
The timestamp server to use. Defaults to
http://timestamp.comodoca.com/authenticode
.LINK
http://www.wintellectnow.com
#>


    [CmdletBinding(SupportsShouldProcess=$true)]
    param
    (
        [Parameter(ValueFromPipeline=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Mandatory=$true,
                   HelpMessage="Please enter the PowerShell files to sign")]
        [Alias('FullName')]
        $Files,
        [ValidateNotNull()]
        $Certificate = @(Get-ChildItem -Path cert:\CurrentUser\My -CodeSigning | 
                            Where-Object { $_.Subject -notlike "*Azure*" } |
                                Select-Object -First 1)[0],
        [ValidateNotNull()]
        $TimeStampServer = "http://timestamp.comodoca.com/authenticode"
    )

    begin
    {
        # Because this is a script file, nothing can come between the params
        # and begin statements. Interestingly, if something does PowerShell
        # ignores the begin and when it hits the process, treats it as the
        # alias Get-Process. :)
        Set-StrictMode -Version Latest
    }
    process
    {
        foreach ($file in $Files)
        {
            # Always support -whatif
            if ($PSCmdlet.ShouldProcess("$_", "Set-AuthenticodeSignature"))   
            {
                Set-AuthenticodeSignature -FilePath $file `
                                          -Certificate $Certificate `
                                          -TimestampServer $TimeStampServer 
            }
        }
    }
}
# SIG # Begin signature block
# MIIYSwYJKoZIhvcNAQcCoIIYPDCCGDgCAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisG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