-
Notifications
You must be signed in to change notification settings - Fork 8
/
sign.ps1
35 lines (28 loc) · 864 Bytes
/
sign.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[CmdletBinding()]
param(
[Parameter()]
[string[]]
$ScriptsToSign,
[Parameter()]
[string]
$TimeStampServer,
[Parameter(ParameterSetName = "File")]
[string]
$CertificatePath,
[Parameter(ParameterSetName = "File")]
[string]
$CertificatePassword,
[Parameter()]
[string]
$CertificateAlgorithm,
[Parameter(ParameterSetName = "Store")]
[string]
$CertificateSubjectName
)
$cert = if ($CertificatePath) {
New-Object System.Security.Cryptography.X509Certificates.X509Certificate2($CertificatePath, $CertificatePassword)
}
else {
Get-ChildItem Cert:\LocalMachine\My | Where-Object Subject -Like "*$CertificateSubjectName*"
}
Set-AuthenticodeSignature -FilePath $ScriptsToSign -Certificate $cert -TimestampServer $TimeStampServer -IncludeChain NotRoot -HashAlgorithm $CertificateAlgorithm