สามารถควบคุมการรันสคริปต์ PowerShell (Script Execution) ได้ผ่าน Group Policy Editor หรือ Registry Editor ใช้สำหรับเพิ่มความปลอดภัยหรืออนุญาตให้รันสคริปต์ตามต้องการ
เปิด/ปิด Script Execution ด้วย Group Policy Editor
- Win+R พิมพ์
gpedit.mscEnter - ไปที่:
Computer Configuration > Administrative Templates > Windows Components > Windows PowerShell - Double-click Turn on Script Execution
- เลือก Enabled เพื่อเปิดใช้งาน / Disabled เพื่อปิด
- หากเลือก Enabled ให้เลือก Execution Policy จาก Dropdown:
- Allow only signed scripts - อนุญาตเฉพาะสคริปต์ที่มี Digital Signature
- Allow local scripts and remote signed scripts (RemoteSigned) - อนุญาตสคริปต์โลคัล และสคริปต์จาก Remote ที่มี Signature
- Allow all scripts (Unrestricted) - อนุญาตทุกสคริปต์ (เสี่ยงที่สุด)
- Apply > OK
เปิด/ปิด Script Execution ด้วย Registry Editor
แนะนำสร้าง System Restore Point และ Backup Registry ก่อน
- Win+R พิมพ์
regeditEnter > Yes - ไปที่:
HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows - คลิกขวา Windows > New > Key > ชื่อ PowerShell
- ใน Key PowerShell สร้าง 2 ค่า:
- DWORD (32-bit) Value ชื่อ EnableScripts > Value: 1 (Enable) / 0 (Disable)
- String Value ชื่อ ExecutionPolicy > Value:
- AllSigned - อนุญาตเฉพาะ Signed scripts
- RemoteSigned - อนุญาต Local + Remote Signed
- Unrestricted - อนุญาตทั้งหมด
- OK แล้วรีสตาร์ทเครื่อง
หมายเหตุ: การตั้งค่า Execution Policy ผ่าน Registry จะมีผลต่อทุก User บนเครื่อง (Machine-wide) ในขณะที่ Set-ExecutionPolicy ใน PowerShell เองจะเป็นต่อ User/Process