-
Notifications
You must be signed in to change notification settings - Fork 54
Expand file tree
/
Copy pathEnable PS Scripts.bat
More file actions
96 lines (86 loc) · 2.98 KB
/
Enable PS Scripts.bat
File metadata and controls
96 lines (86 loc) · 2.98 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
@echo off
setlocal EnableDelayedExpansion
:: Check for administrator privileges
net session >nul 2>&1
if %errorLevel% NEQ 0 (
echo.
echo ========================================
echo ERROR: Administrator rights required!
echo ========================================
echo.
echo This script must be run as Administrator to modify registry settings.
echo.
echo Right-click this file and select "Run as administrator"
echo.
pause
exit /b 1
)
echo.
echo ========================================
echo PowerShell Script Enabler
echo ========================================
echo.
echo This script will:
echo - Set PowerShell execution policy to Unrestricted
echo - Enable script execution in Windows policies
echo - Unblock all .ps1 files in this folder
echo.
echo WARNING: This reduces security. Only proceed if you trust
echo the PowerShell scripts in this directory.
echo.
choice /M "Do you wish to proceed"
if errorlevel 2 goto abort
echo.
echo [1/4] Setting ExecutionPolicy in PowerShell registry...
Reg.exe add "HKLM\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell" /v "ExecutionPolicy" /t REG_SZ /d "Unrestricted" /f >nul 2>&1
if %errorlevel% NEQ 0 (
echo [FAILED] Could not modify PowerShell registry key
goto abort
)
echo [OK] PowerShell ExecutionPolicy set to Unrestricted
echo.
echo [2/4] Setting ExecutionPolicy in Windows Policies...
Reg.exe add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "ExecutionPolicy" /t REG_SZ /d "Unrestricted" /f >nul 2>&1
if %errorlevel% NEQ 0 (
echo [WARNING] Could not set ExecutionPolicy in Policies ^(may not exist^)
) else (
echo [OK] Windows Policies ExecutionPolicy set
)
echo.
echo [3/4] Enabling script execution in Windows Policies...
Reg.exe add "HKLM\Software\Policies\Microsoft\Windows\PowerShell" /v "EnableScripts" /t REG_DWORD /d "1" /f >nul 2>&1
if %errorlevel% NEQ 0 (
echo [WARNING] Could not enable scripts in Policies ^(may not exist^)
) else (
echo [OK] Script execution enabled
)
echo.
echo [4/4] Unblocking PowerShell scripts in current directory...
PowerShell -NoProfile -ExecutionPolicy Bypass -Command "Get-ChildItem -Path '%~dp0' -Recurse -Filter '*.ps1' | Unblock-File -Confirm:$false"
if %errorlevel% NEQ 0 (
echo [WARNING] Failed to unblock some files
) else (
echo [OK] All .ps1 files unblocked
)
echo.
echo ========================================
echo SUCCESS! PowerShell scripts enabled.
echo ========================================
echo.
echo You can now run PowerShell scripts (.ps1 files) without restrictions.
echo.
goto end
:abort
echo.
echo ========================================
echo Script execution aborted or failed
echo ========================================
echo.
echo Possible reasons:
echo - Not running as Administrator
echo - Registry keys are protected by Group Policy
echo - Antivirus blocking registry changes
echo.
:end
pause
exit /b 0