Skip to content

Commit 314de10

Browse files
committed
Update winstuff.md
1 parent 0ae5430 commit 314de10

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

operating-systems/windows/winstuff.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,40 @@ taskkill /PID targetpid
307307

308308
## Powershell commands
309309

310+
### PS1 Scripts
311+
312+
```powershell
313+
# 1. Run the script with Bypass mode (One-time execution)
314+
powershell -ExecutionPolicy Bypass -File <SCRIPT.ps1>
315+
# Shorter version
316+
powershell -ep Bypass -f <SCRIPT.ps1>
317+
318+
# 2. Temporarily set execution policy for the current session
319+
Set-ExecutionPolicy Bypass -Scope Process -Force
320+
<SCRIPT.ps1> # Now run the script
321+
322+
# 3. Unblock the script file (if marked as untrusted)
323+
Unblock-File -Path <SCRIPT.ps1>
324+
<SCRIPT.ps1> # Try running again
325+
326+
# 4. Run the script without changing execution policy (using Invoke-Expression)
327+
powershell -Command "Get-Content <SCRIPT.ps1> | Invoke-Expression"
328+
# Alternative (more compact)
329+
iex (Get-Content <SCRIPT.ps1> -Raw)
330+
331+
# 5. Change execution policy permanently (requires admin)
332+
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force # Allows all scripts
333+
Set-ExecutionPolicy RemoteSigned -Scope LocalMachine -Force # Allows only signed remote scripts
334+
335+
# 6. Run with -NoProfile to ignore execution policies
336+
powershell -NoProfile -ExecutionPolicy Bypass -File <SCRIPT.ps1>
337+
338+
# 7. Reset execution policy back to restricted (optional, for security)
339+
Set-ExecutionPolicy Restricted -Scope CurrentUser -Force # Blocks all scripts again
340+
```
341+
342+
343+
310344
### [Winget](https://learn.microsoft.com/en-us/windows/package-manager/winget/upgrade)
311345

312346
```bash

0 commit comments

Comments
 (0)