hashicorp/vagrant · error · VagrantPlugins::HyperV::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

The Hyper-V driver executes helper PowerShell scripts and parses their stdout; when the output matches ERROR_REGEXP, the embedded JSON blob is parsed and its 'error' payload is re-raised as PowerShellError. This path means the script itself caught a failure and reported it through Vagrant's structured error channel — the real cause is in the stderr field of the message.

Source

Thrown at plugins/providers/hyperv/driver.rb:66

      #                       nil will be returned
      def execute(path, options={})
        if path.is_a?(Symbol)
          path = "#{path}.ps1"
        end
        r = execute_powershell(path, options)

        # We only want unix-style line endings within Vagrant
        r.stdout.gsub!("\r\n", "\n")
        r.stderr.gsub!("\r\n", "\n")

        error_match  = ERROR_REGEXP.match(r.stdout)
        output_match = OUTPUT_REGEXP.match(r.stdout)

        if error_match
          data = JSON.parse(error_match[1])

          # We have some error data.
          raise Errors::PowerShellError,
            script: path,
            stderr: data["error"]
        end

        if r.exit_code != 0
          raise Errors::PowerShellError,
            script: path,
            stderr: r.stderr
        end

        # Nothing
        return nil if !output_match
        return JSON.parse(output_match[1])
      end

      # Fetch current state of the VM
      #
      # @return [Hash<state, status>]

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. Read the Script/Error lines in the message — they name the failing .ps1 and the underlying Hyper-V error, which is the actual problem to fix
  2. Restart the Hyper-V management service: `net stop vmms && net start vmms` (or `Restart-Service vmms`) and retry
  3. Run the terminal as Administrator so the PowerShell helpers can manage the VM
  4. Verify the Hyper-V feature and Windows Management Framework are installed and the host was not mid-upgrade; if the config looks right, report a bug to Vagrant with the script output

Example fix

# diagnose the underlying failure the wrapper surfaced
# message shows: Script: .../import_vm.ps1  Error: <hyper-v text>
# reproduce manually in an elevated PowerShell:
#   & 'C:\HashiCorp\Vagrant\embedded\gems\...\import_vm.ps1' -VmConfigFile ... 
# fix what it reports (e.g. start service: Restart-Service vmms), then re-run vagrant up
Defensive patterns

Strategy: try-catch

Validate before calling

# cheap pre-flight on Windows hosts
system('powershell -NoProfile -Command "Get-Service vmms | Where-Object {$_.Status -ne \'Running\'}"')
raise 'Hyper-V VMMS not running' unless $?.success?

Try / catch

begin
  with_environment(env) { env.cli('up') }
rescue Vagrant::Errors::PowerShellError => e
  # e.extra_data[:stderr] holds the real Hyper-V error; e.extra_data[:script] names the helper
  log_hyperv_failure(script: e.extra_data[:script], stderr: e.extra_data[:stderr])
  retry_once_after(:restart_vmms) if e.extra_data[:stderr] =~ /vmms|service/i
end

Prevention

When it happens

Trigger: Any Hyper-V driver operation during `vagrant up`/`halt`/`reload`/snapshot commands: the PS helper (e.g. import_vm.ps1, start_vm.ps1) writes an error JSON object to stdout, JSON.parse extracts data['error'], and the error is raised with script: path, stderr: data['error'].

Common situations: Hyper-V Virtual Machine Management service (vmms) not running; VM or switch in a bad state; running Vagrant in a non-elevated shell when the operation needs administrator rights; Vagrantlink/network name collisions on the host.

Related errors


AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21). Data as JSON: /api/errors/10a4605591f8984d. Report an issue: GitHub.