Skip to content

Commit 0630e49

Browse files
Update EP10 - PowerShell Script.ps1
1 parent 6d95239 commit 0630e49

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

LearnPowerShell/EP10 - PowerShell Script.ps1

+55
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,68 @@
1212

1313
#endregion
1414

15+
PowerShell's execution policy
16+
security feature
17+
controls the conditions under which PowerShell can run scripts.
18+
A safety net to prevent the execution of malicious scripts,
19+
Not a foolproof security measure (a determined user can bypass it).
20+
Just a first line of defense.  
21+
22+
Here's a breakdown of key aspects:
23+
24+
What it does:
25+
26+
The execution policy
27+
determines whether you can run scripts at all,
28+
if so, under what conditions.
29+
Makes it harder for untrusted scripts to run accidentally or unknowingly.  
30+
31+
Different Execution Policies:
32+
33+
PowerShell defines several execution policies, each with different levels of restrictiveness:  
34+
35+
Restricted (Default):
36+
No scripts can be run.
37+
Most restrictive policy.
38+
You can still run individual commands interactively, but not scripts.  
39+
40+
AllSigned:
41+
All scripts must be signed by a trusted publisher.
42+
Most secure policy
43+
but can be inconvenient if you're working with scripts from various sources.  
44+
45+
RemoteSigned:
46+
Scripts downloaded from the internet
47+
must be signed by a trusted publisher.
48+
Locally created scripts can run without a signature.
49+
This is a common and often recommended balance between security and usability.  
50+
51+
Bypass:
52+
No restrictions.
53+
All scripts can run without a signature.
54+
Use this only if you
55+
completely trust all the scripts you're running
56+
understand the security implications.
57+
It's generally not recommended for regular use.
58+
59+
Unrestricted:
60+
All scripts can run, even unsigned ones.
61+
Similar to Bypass,
62+
but it also warns you before running unsigned scripts.
63+
Less restrictive than Bypass,
64+
but still not recommended for general use unless you have a very specific reason.  
65+
66+
67+
68+
1569
#region running scripts
1670
1771
#get the execution policy of all scopes in the order of precedence
1872
Get-ExecutionPolicy -List
1973
2074
#change execution policy
2175
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
76+
#Set-ExecutionPolicy <PolicyName> -Scope <Scope> -Force
2277
2378
#unblock a script downloaded from the internet after you have read and understood the code
2479
Unblock-File -Path .\drive_warn.ps1

0 commit comments

Comments
 (0)