{"record":{"id":"268a12d4d5d05b05","repo":"hashicorp/vagrant","slug":"an-error-occurred-while-executing-a-powershell-scr-268a12","errorCode":null,"errorMessage":"An error occurred while executing a PowerShell script. This error\nis shown below. Please read the error message and see if this is\na configuration error with your system. If it is not, then please\nreport a bug.\n\nScript: %{script}\nError:\n\n%{stderr}","messagePattern":"An error occurred while executing a PowerShell script\\. This error\nis shown below\\. Please read the error message and see if this is\na configuration error with your system\\. If it is not, then please\nreport a bug\\.\n\nScript: %(.+?)\nError:\n\n%(.+?)","errorType":"exception","errorClass":"Vagrant::Errors::PowerShellError","httpStatus":null,"severity":"error","filePath":"plugins/hosts/windows/cap/ssh.rb","lineNumber":20,"sourceCode":"# SPDX-License-Identifier: BUSL-1.1\n\nmodule VagrantPlugins\n  module HostWindows\n    module Cap\n      class SSH\n        # Set the ownership and permissions for SSH\n        # private key\n        #\n        # @param [Vagrant::Environment] env\n        # @param [Pathname] key_path\n        def self.set_ssh_key_permissions(env, key_path)\n          script_path = Host.scripts_path.join(\"set_ssh_key_permissions.ps1\")\n          result = Vagrant::Util::PowerShell.execute(\n            script_path.to_s, \"-KeyPath\", key_path.to_s.gsub(' ', '` '),\n            module_path: Host.modules_path.to_s\n          )\n          if result.exit_code != 0\n            raise Vagrant::Errors::PowerShellError,\n              script: script_path,\n              stderr: result.stderr\n          end\n          result\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":2,"sourceCodeEnd":30,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/hosts/windows/cap/ssh.rb#L2-L30","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Windows pre-flight: scripts can execute under the modules path\nraise \"PowerShell unavailable\" unless Vagrant::Util::PowerShell.available?\nok = system(\"powershell -NoProfile -ExecutionPolicy Bypass -Command \\\"exit 0\\\"\")\nabort \"Set ExecutionPolicy RemoteSigned (CurrentUser) before using Vagrant keys\" unless ok","typeGuard":null,"tryCatchPattern":"begin\n  HostWindows::Cap::SSH.set_ssh_key_permissions(env, key_path)\nrescue Vagrant::Errors::PowerShellError => e\n  puts \"#{e.data[:script]} failed:\\n#{e.data[:stderr]}\"\n  # fix execution policy / AV lock, then retry once\n  retry if fixed_and_retryable?\nend","preventionTips":["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"],"tags":["windows","powershell","ssh-key","permissions","execution-policy"],"backgroundTag":"powershell-script-failed","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}