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 in plugins/hosts/windows/cap/configured_ip_addresses.rb:21. The Windows host capability enumerates the host's IP addresses (used for NFS/network setup) by executing scripts/host_info.ps1 via Vagrant::Util::PowerShell and parsing its JSON stdout; a non-zero exit raises with the script path and stderr.

Source

Thrown at plugins/hosts/windows/cap/configured_ip_addresses.rb:21

require "pathname"
require "tempfile"

require "vagrant/util/downloader"
require "vagrant/util/file_checksum"
require "vagrant/util/powershell"
require "vagrant/util/subprocess"

module VagrantPlugins
  module HostWindows
    module Cap
      class ConfiguredIPAddresses

        def self.configured_ip_addresses(env)
          script_path = File.expand_path("../../scripts/host_info.ps1", __FILE__)
          r = Vagrant::Util::PowerShell.execute(script_path)
          if r.exit_code != 0
            raise Vagrant::Errors::PowerShellError,
              script: script_path,
              stderr: r.stderr
          end

          res = JSON.parse(r.stdout)["ip_addresses"]
          Array(res)
        end
      end
    end
  end
end

View on GitHub (pinned to 35f3160f4a)

Solutions

  1. Run the exact Script path from the error in a PowerShell window to see the real error
  2. Allow local scripts: `Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`
  3. Repair the WMI repository if network cmdlets fail (`winmgmt /verifyrepository`, then /salvage if needed)
  4. Update Vagrant; exclude the script from AV interference
Defensive patterns

Strategy: validation

Validate before calling

# Windows pre-flight: PowerShell present and scripts can run
raise "PowerShell unavailable" unless Vagrant::Util::PowerShell.available?
ps_ok = system("powershell -NoProfile -ExecutionPolicy Bypass -Command \"[Net.NetworkInformation.NetworkInterface]::GetAllNetworkInterfaces() | Out-Null\"")
abort "PowerShell/network cmdlets broken — check ExecutionPolicy and WMI" unless ps_ok

Try / catch

begin
  capability.call(:configured_ip_addresses, env)
rescue Vagrant::Errors::PowerShellError => e
  puts "host_info.ps1 failed:\n#{e.data[:stderr]}"
  # guide user to Set-ExecutionPolicy / WMI repair, then retry
  raise
end

Prevention

When it happens

Trigger: On a Windows host, any operation needing host IPs runs host_info.ps1; it exits non-zero when the PowerShell execution policy blocks unsigned scripts, the PS installation/module path is broken, or the network cmdlets inside (Get-NetIPAddress etc.) fail.

Common situations: ExecutionPolicy Restricted on locked-down machines; a corrupted $env:PSModulePath; WMI/NetTCPIP repository damage; antivirus interfering with script execution.

Related errors


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