Powershell: check if the executionpolicy allow to run safe-chain

This commit is contained in:
Sander Declerck 2026-02-04 16:30:29 +01:00
parent 611fe8007f
commit c765438e63
No known key found for this signature in database

View file

@ -31,6 +31,28 @@ function Write-Error-Custom {
exit 1 exit 1
} }
# Check if the PowerShell execution policy allows script execution
function Test-ExecutionPolicy {
$policy = Get-ExecutionPolicy
$acceptablePolicies = @('RemoteSigned', 'Unrestricted', 'Bypass')
return $acceptablePolicies -contains $policy
}
if (-not (Test-ExecutionPolicy)) {
$currentPolicy = Get-ExecutionPolicy
Write-Error-Custom @"
PowerShell execution policy is set to '$currentPolicy', which prevents safe-chain from running.
The execution policy must be at least 'RemoteSigned' to allow safe-chain's initialization script to run.
To fix this, open PowerShell as Administrator and run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
Then restart this installation.
"@
}
# Get currently installed version of safe-chain # Get currently installed version of safe-chain
function Get-InstalledVersion { function Get-InstalledVersion {
# Check if safe-chain command exists # Check if safe-chain command exists
@ -157,7 +179,8 @@ function Install-SafeChain {
Write-Warn "" Write-Warn ""
if ($ci) { if ($ci) {
Write-Warn " iex `"& { `$(iwr 'https://github.com/AikidoSec/safe-chain/releases/download/$env:SAFE_CHAIN_VERSION/install-safe-chain.ps1' -UseBasicParsing) } -ci`"" Write-Warn " iex `"& { `$(iwr 'https://github.com/AikidoSec/safe-chain/releases/download/$env:SAFE_CHAIN_VERSION/install-safe-chain.ps1' -UseBasicParsing) } -ci`""
} else { }
else {
Write-Warn " iex (iwr `"https://github.com/AikidoSec/safe-chain/releases/download/$env:SAFE_CHAIN_VERSION/install-safe-chain.ps1`" -UseBasicParsing)" Write-Warn " iex (iwr `"https://github.com/AikidoSec/safe-chain/releases/download/$env:SAFE_CHAIN_VERSION/install-safe-chain.ps1`" -UseBasicParsing)"
} }
Write-Warn "" Write-Warn ""