hashicorp/vagrant · error · Vagrant::Errors::PowerShellError
An error occurred while executing a PowerShell script. This
Error message
An error occurred while executing a PowerShell script. This error
is shown below. Please read the error message and see if this is
a configuration error with your system. If it is not, then please
report a bug.
Script: %{script}
Error:
%{stderr} What it means
Vagrant::Errors::PowerShellError raised at plugins/hosts/windows/cap/ssh.rb:20 in set_ssh_key_permissions. After Vagrant writes a machine's private key on Windows, it tightens the ACL by running scripts/set_ssh_key_permissions.ps1 with `-KeyPath <path>` (spaces backtick-escaped) and the host's modules_path; a non-zero exit raises with the script path and stderr.
Source
Thrown at plugins/hosts/windows/cap/ssh.rb:20
# SPDX-License-Identifier: BUSL-1.1
module VagrantPlugins
module HostWindows
module Cap
class SSH
# Set the ownership and permissions for SSH
# private key
#
# @param [Vagrant::Environment] env
# @param [Pathname] key_path
def self.set_ssh_key_permissions(env, key_path)
script_path = Host.scripts_path.join("set_ssh_key_permissions.ps1")
result = Vagrant::Util::PowerShell.execute(
script_path.to_s, "-KeyPath", key_path.to_s.gsub(' ', '` '),
module_path: Host.modules_path.to_s
)
if result.exit_code != 0
raise Vagrant::Errors::PowerShellError,
script: script_path,
stderr: result.stderr
end
result
end
end
end
end
end
View on GitHub (pinned to 35f3160f4a)
Solutions
- Run the printed Script in PowerShell to see the underlying error
- Set `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`
- Exclude the project's .vagrant directory (and key files) from real-time AV scanning
- Reinstall/repair Vagrant so scripts and modules are present and consistent
Defensive patterns
Strategy: validation
Validate before calling
# Windows pre-flight: scripts can execute under the modules path
raise "PowerShell unavailable" unless Vagrant::Util::PowerShell.available?
ok = system("powershell -NoProfile -ExecutionPolicy Bypass -Command \"exit 0\"")
abort "Set ExecutionPolicy RemoteSigned (CurrentUser) before using Vagrant keys" unless ok Try / catch
begin
HostWindows::Cap::SSH.set_ssh_key_permissions(env, key_path)
rescue Vagrant::Errors::PowerShellError => e
puts "#{e.data[:script]} failed:\n#{e.data[:stderr]}"
# fix execution policy / AV lock, then retry once
retry if fixed_and_retryable?
end Prevention
- Set ExecutionPolicy RemoteSigned for the vagrant user
- Avoid spaces/unicode in the project path on Windows hosts (backtick escaping is fragile)
- Exclude .vagrant/ key files from real-time AV scanning
When it happens
Trigger: `vagrant up` on a Windows host reaches key-permission setup and the PS script fails: execution policy blocks the unsigned script, antivirus locks the freshly written key, the path contains characters that break the backtick-space escaping, or the Vagrant install's modules are missing.
Common situations: ExecutionPolicy Restricted; AV scanning/quarantining private keys; project paths with spaces or unicode; a half-updated Vagrant install whose scripts/modules are out of sync.
Related errors
- An error occurred while executing a PowerShell script. This
- Vagrant failed to copy the default insecure private key into
- Failed to locate the powershell executable on the available
- The version of powershell currently installed on this host i
- A command must be provided when the --elevated flag is provi
AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21).
Data as JSON: /api/errors/268a12d4d5d05b05.
Report an issue: GitHub.