Skip to content

Commit 4e64e94

Browse files
authored
Create AutoSign.ps1
1 parent e29e3a5 commit 4e64e94

1 file changed

Lines changed: 196 additions & 0 deletions

File tree

AutoSign/v1.3.0/EN/AutoSign.ps1

Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
param([switch]$Elevated)
2+
3+
function Test-Admin {
4+
$currentUser = New-Object Security.Principal.WindowsPrincipal $([Security.Principal.WindowsIdentity]::GetCurrent())
5+
$currentUser.IsInRole([Security.Principal.WindowsBuiltinRole]::Administrator)
6+
}
7+
# Function to see if user is an admin
8+
function prompt{
9+
if ((Test-Admin) -eq $false) {
10+
if ($elevated) {
11+
} else {
12+
Start-Process powershell.exe -Verb RunAs -ArgumentList ('-noprofile -file "{0}" -elevated' -f ($myinvocation.MyCommand.Definition))
13+
}
14+
}
15+
}
16+
# Launch admin prompt
17+
18+
$CertCodeSigning = Get-ChildItem Cert:\CurrentUser\TrustedPublisher\ -CodeSigningCert
19+
# Certificate able to sign scripts
20+
$TimestampServer = "http://timestamp.comodoca.com/authenticode"
21+
# Date and time
22+
23+
function sign{
24+
Set-AuthenticodeSignature $ScriptToSign -Certificate $CertCodeSigning -TimestampServer $TimestampServer
25+
# Sign the script
26+
27+
Write-Host "`nYour script is now signed `n"
28+
29+
pause
30+
exit
31+
}
32+
33+
function fichier1{
34+
35+
Clear-Host
36+
37+
$file1 = Read-Host "Enter the name of your PowerShell script"
38+
39+
$ScriptToSign = "C:\Script\$file1.ps1"
40+
41+
sign
42+
}
43+
44+
function dossier2{
45+
46+
Clear-Host
47+
48+
$ScriptToSign = "C:\Script\*.ps1"
49+
50+
sign
51+
}
52+
53+
function fichier3{
54+
55+
Clear-Host
56+
57+
$file3 = Read-Host "Filepath of your PowerShell script"
58+
$ScriptToSign = "$file3.ps1"
59+
60+
sign
61+
}
62+
63+
function dossier4{
64+
65+
Clear-Host
66+
67+
$dir4 = Read-Host "Path of your directory"
68+
$ScriptToSign = "$dir4\*.ps1"
69+
70+
sign
71+
}
72+
73+
function fichier5{
74+
75+
Clear-Host
76+
77+
prompt
78+
79+
$file5 = Read-Host "Enter the name of your PowerShell script"
80+
81+
$ScriptToSign = "C:\Script\$file5.ps1"
82+
83+
sign
84+
}
85+
86+
function dossier6{
87+
88+
Clear-Host
89+
90+
prompt
91+
92+
$ScriptToSign = "C:\Script\*.ps1"
93+
94+
sign
95+
}
96+
97+
function fichier7{
98+
99+
Clear-Host
100+
101+
prompt
102+
103+
$file7 = Read-Host "Filepath of the PowerShell script"
104+
$ScriptToSign = "$file7.ps1"
105+
106+
sign
107+
}
108+
109+
function dossier8{
110+
111+
Clear-Host
112+
113+
prompt
114+
115+
$dir8 = Read-Host "Path of the directory"
116+
$ScriptToSign = "$dir8\*.ps1"
117+
118+
sign
119+
}
120+
121+
function menu{
122+
123+
124+
Write-Host "##############################################"
125+
126+
Write-Host "
127+
_ _____ _
128+
/\ | | / ____(_)
129+
/ \ _ _| |_ ___| (___ _ __ _ _ __
130+
/ /\ \| | | | __/ _ \\___ \| |/ _` | '_ \
131+
/ ____ \ |_| | || (_) |___) | | (_| | | | |
132+
/_/ \_\__,_|\__\___/_____/|_|\__, |_| |_|
133+
__/ |
134+
|___/
135+
136+
137+
"
138+
139+
Write-Host "############################################## `n"
140+
141+
142+
Write-Host "This script allow you to AutoSign your PowerShell scripts `n"
143+
144+
Write-Host "Your scripts :`n"
145+
Write-Host "1 : File"
146+
Write-Host "2 : Directory `n"
147+
Write-Host "3 : Specific File"
148+
Write-Host "4 : Specific directory `n"
149+
150+
Write-Host "All scripts (admin) :`n"
151+
Write-Host "5 : File"
152+
Write-Host "6 : Directory `n"
153+
Write-Host "7 : Specific File"
154+
Write-Host "8 : Specific Directory`n"
155+
156+
157+
Write-Host "9 : Exit `n"
158+
}
159+
menu
160+
do{
161+
$choix = Read-Host "Choose your option"
162+
163+
switch($choix){
164+
"1"{
165+
fichier1
166+
}
167+
"2"{
168+
dossier2
169+
}
170+
"3"{
171+
fichier3
172+
}
173+
"4"{
174+
dossier4
175+
}
176+
"5"{
177+
fichier5
178+
}
179+
"6"{
180+
dossier6
181+
}
182+
"7"{
183+
fichier7
184+
}
185+
"8"{
186+
dossier8
187+
}
188+
"9"{
189+
exit
190+
}
191+
default {
192+
Write-Host "Choix invalide"
193+
}
194+
}
195+
196+
} while($true)

0 commit comments

Comments
 (0)