Import module for execution policy

This commit is contained in:
Sander Declerck 2026-02-05 10:12:43 +01:00
parent ad32a8d9be
commit 3e90c0abd1
No known key found for this signature in database

View file

@ -258,11 +258,15 @@ export function validatePowerShellExecutionPolicy(shellExecutableName) {
try {
// Security: Use literal command string, no interpolation
const policy = execSync('-Command "Get-ExecutionPolicy"', {
encoding: "utf8",
shell: shellExecutableName,
timeout: 5000, // 5 second timeout
}).trim();
// Import the Security module first - works for both powershell.exe and pwsh.exe
const policy = execSync(
"Import-Module Microsoft.PowerShell.Security; Get-ExecutionPolicy",
{
encoding: "utf8",
shell: shellExecutableName,
timeout: 5000, // 5 second timeout
}
).trim();
const acceptablePolicies = ["RemoteSigned", "Unrestricted", "Bypass"];
return {