{"record":{"id":"e8af6b487b20a587","repo":"hashicorp/vagrant","slug":"a-command-must-be-provided-when-the-elevated-fla","errorCode":null,"errorMessage":"A command must be provided when the --elevated flag is provided for the powershell command. Please provide a command when using the --elevated flag and try again.","messagePattern":"A command must be provided when the --elevated flag is provided for the powershell command\\. Please provide a command when using the --elevated flag and try again\\.","errorType":"exception","errorClass":"VagrantPlugins::CommandPS::Errors::ElevatedNoCommand","httpStatus":null,"severity":"error","filePath":"plugins/commands/powershell/command.rb","lineNumber":51,"sourceCode":"          o.on(\"-e\", \"--elevated\", \"Execute a powershell command with elevated permissions\") do |c|\n            options[:elevated] = true\n          end\n        end\n\n        # Parse out the extra args to send to the ps session, which\n        # is everything after the \"--\"\n        split_index = @argv.index(\"--\")\n        if split_index\n          options[:extra_args] = @argv.drop(split_index + 1)\n          @argv                = @argv.take(split_index)\n        end\n\n        # Parse the options and return if we don't have any target.\n        argv = parse_options(opts)\n        return if !argv\n\n        # Elevated option enabled means we can only execute commands\n        raise Errors::ElevatedNoCommand if !options[:command] && options[:elevated]\n\n        # Execute ps session if we can\n        with_target_vms(argv, single_target: true) do |machine|\n          if !machine.communicate.ready?\n            raise Vagrant::Errors::VMNotCreatedError\n          end\n\n          if options[:command]\n            if machine.config.vm.communicator != :winrm\n              raise VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady\n            end\n\n            out_code = machine.communicate.execute(options[:command].dup, elevated: options[:elevated]) do |type,data|\n              machine.ui.detail(data) if type == :stdout\n            end\n            if out_code == 0\n              machine.ui.success(\"Command: #{options[:command]} executed successfully with output code #{out_code}.\")\n            end","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/hashicorp/vagrant/blob/35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5/plugins/commands/powershell/command.rb#L33-L69","documentation":"In `vagrant powershell`, the --elevated flag only applies to command execution mode. After option parsing, if options[:command] is nil while options[:elevated] is true, Vagrant raises Errors::ElevatedNoCommand: elevated interactive PowerShell sessions are not supported, so a --command is mandatory when elevating.","triggerScenarios":"`vagrant powershell --elevated` with no --command; passing the intended script after `--` (which only becomes extra_args for the session) instead of via --command; flag order is irrelevant, the combination is what fails.","commonSituations":"Expecting --elevated to open an elevated interactive shell on the guest; provisioning scripts that set the elevation flag but build the command string conditionally and end up empty.","solutions":["Add --command: `vagrant powershell --elevated --command \"choco install -y git\"`.","Drop --elevated if you want an interactive session (only from a Windows host with ps_client capability).","Check `vagrant powershell -h` for the exact flag names on your Vagrant version."],"exampleFix":"# before\nvagrant powershell --elevated\n# after\nvagrant powershell --elevated --command \"choco install -y git\"","handlingStrategy":"validation","validationCode":"if ARGV.include?('--elevated') && !ARGV.include?('--command')\n  abort '--elevated requires --command \"...\"'\nend\nsystem('vagrant', 'powershell', *ARGV)","typeGuard":null,"tryCatchPattern":"begin\n  Vagrant::Environment.new.cli(['powershell', '--elevated', '--command', cmd])\nrescue VagrantPlugins::CommandPowershell::Errors::ElevatedNoCommand => e\n  warn e.message # attach a --command or drop --elevated\n  exit 1\nend","preventionTips":["Treat --elevated as a modifier of --command, never a standalone mode.","Build command strings eagerly and fail if they end up nil/empty.","Smoke-test automation with a trivial `--command \"whoami\"` first."],"tags":["vagrant","powershell","elevated","cli","windows"],"backgroundTag":"missing-required-option","analyzedSha":"35f3160f4ad6edc3a9f3aa9570adfc1a4d73aaa5","analyzedAt":"2026-08-21T13:34:32.514Z","schemaVersion":2},"datasetVersion":"2026-08-21T18:17:14.833Z"}