{"record":{"id":"10a4605591f8984d","repo":"hashicorp/vagrant","slug":"an-error-occurred-while-executing-a-powershell-scr-10a460","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":"VagrantPlugins::HyperV::Errors::PowerShellError","httpStatus":null,"severity":"error","filePath":"plugins/providers/hyperv/driver.rb","lineNumber":66,"sourceCode":"      #                       nil will be returned\n      def execute(path, options={})\n        if path.is_a?(Symbol)\n          path = \"#{path}.ps1\"\n        end\n        r = execute_powershell(path, options)\n\n        # We only want unix-style line endings within Vagrant\n        r.stdout.gsub!(\"\\r\\n\", \"\\n\")\n        r.stderr.gsub!(\"\\r\\n\", \"\\n\")\n\n        error_match  = ERROR_REGEXP.match(r.stdout)\n        output_match = OUTPUT_REGEXP.match(r.stdout)\n\n        if error_match\n          data = JSON.parse(error_match[1])\n\n          # We have some error data.\n          raise Errors::PowerShellError,\n            script: path,\n            stderr: data[\"error\"]\n        end\n\n        if r.exit_code != 0\n          raise Errors::PowerShellError,\n            script: path,\n            stderr: r.stderr\n        end\n\n        # Nothing\n        return nil if !output_match\n        return JSON.parse(output_match[1])\n      end\n\n      # Fetch current state of the VM\n      #\n      # @return [Hash<state, status>]","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/providers/hyperv/driver.rb#L48-L84","documentation":"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.","triggerScenarios":"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'].","commonSituations":"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.","solutions":["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","Restart the Hyper-V management service: `net stop vmms && net start vmms` (or `Restart-Service vmms`) and retry","Run the terminal as Administrator so the PowerShell helpers can manage the VM","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"],"exampleFix":"# diagnose the underlying failure the wrapper surfaced\n# message shows: Script: .../import_vm.ps1  Error: <hyper-v text>\n# reproduce manually in an elevated PowerShell:\n#   & 'C:\\HashiCorp\\Vagrant\\embedded\\gems\\...\\import_vm.ps1' -VmConfigFile ... \n# fix what it reports (e.g. start service: Restart-Service vmms), then re-run vagrant up","handlingStrategy":"try-catch","validationCode":"# cheap pre-flight on Windows hosts\nsystem('powershell -NoProfile -Command \"Get-Service vmms | Where-Object {$_.Status -ne \\'Running\\'}\"')\nraise 'Hyper-V VMMS not running' unless $?.success?","typeGuard":null,"tryCatchPattern":"begin\n  with_environment(env) { env.cli('up') }\nrescue Vagrant::Errors::PowerShellError => e\n  # e.extra_data[:stderr] holds the real Hyper-V error; e.extra_data[:script] names the helper\n  log_hyperv_failure(script: e.extra_data[:script], stderr: e.extra_data[:stderr])\n  retry_once_after(:restart_vmms) if e.extra_data[:stderr] =~ /vmms|service/i\nend","preventionTips":["Run Vagrant from an elevated shell on Hyper-V hosts","Pre-flight check that the vmms service is running before scripted vagrant up","Keep Hyper-V/Vagrant versions in lockstep and pin both in provisioning docs"],"tags":["hyperv","powershell","windows","driver"],"backgroundTag":"powershell-script-failure","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}