-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSign-PowershellCertGui.ps1
27 lines (22 loc) · 1.07 KB
/
Sign-PowershellCertGui.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
function Sign-PowershellCertGui{
<#
.SYNOPSIS
Sign-PowershellCertGui is a powershell function to assist in signing ps1 files.
.DESCRIPTION
Sign-PowershellCertGui is a powershell function to assist in signing ps1 files.
First, browse to and open the powershell script, then, browse and open the pfx file.
#>
Add-Type -AssemblyName System.Windows.Forms
$FileBrowser = [System.Windows.Forms.OpenFileDialog]::new()
$FileBrowser.InitialDirectory = [Environment]::GetFolderPath('Desktop')
$FileBrowser.Filter = 'Powershell Scripts (*.ps1)|*.ps1'
$null = $FileBrowser.ShowDialog()
$script = $FileBrowser.FileName
$FileBrowser = [System.Windows.Forms.OpenFileDialog]::new()
$FileBrowser.InitialDirectory = [Environment]::GetFolderPath('Desktop')
$FileBrowser.Filter = 'Personal Information Exchange Files (*.pfx)|*.pfx'
$null = $FileBrowser.ShowDialog()
$file = $FileBrowser.FileName
$MyCertFromPfx = Get-PfxCertificate -FilePath $file
Set-AuthenticodeSignature -PSPath $script -Certificate $MyCertFromPfx
}