hashicorp/vagrant · error · VagrantPlugins::CommandPS::Errors::ElevatedNoCommand
A command must be provided when the --elevated flag is provi
Error message
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.
What it means
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.
Source
Thrown at plugins/commands/powershell/command.rb:51
o.on("-e", "--elevated", "Execute a powershell command with elevated permissions") do |c|
options[:elevated] = true
end
end
# Parse out the extra args to send to the ps session, which
# is everything after the "--"
split_index = @argv.index("--")
if split_index
options[:extra_args] = @argv.drop(split_index + 1)
@argv = @argv.take(split_index)
end
# Parse the options and return if we don't have any target.
argv = parse_options(opts)
return if !argv
# Elevated option enabled means we can only execute commands
raise Errors::ElevatedNoCommand if !options[:command] && options[:elevated]
# Execute ps session if we can
with_target_vms(argv, single_target: true) do |machine|
if !machine.communicate.ready?
raise Vagrant::Errors::VMNotCreatedError
end
if options[:command]
if machine.config.vm.communicator != :winrm
raise VagrantPlugins::CommunicatorWinRM::Errors::WinRMNotReady
end
out_code = machine.communicate.execute(options[:command].dup, elevated: options[:elevated]) do |type,data|
machine.ui.detail(data) if type == :stdout
end
if out_code == 0
machine.ui.success("Command: #{options[:command]} executed successfully with output code #{out_code}.")
endView on GitHub (pinned to 35f3160f4a)
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.
Example fix
# before vagrant powershell --elevated # after vagrant powershell --elevated --command "choco install -y git"
Defensive patterns
Strategy: validation
Validate before calling
if ARGV.include?('--elevated') && !ARGV.include?('--command')
abort '--elevated requires --command "..."'
end
system('vagrant', 'powershell', *ARGV) Try / catch
begin Vagrant::Environment.new.cli(['powershell', '--elevated', '--command', cmd]) rescue VagrantPlugins::CommandPowershell::Errors::ElevatedNoCommand => e warn e.message # attach a --command or drop --elevated exit 1 end
Prevention
- 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.
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- Your host does not support PowerShell. A remote PowerShell c
- The Hyper-V cmdlets for PowerShell are not available! Vagran
- You requested to remove the box '%{name}' version '%{version
- The box you're attempting to add already exists. Remove it b
- Failed to locate the powershell executable on the available
AI-assisted analysis of hashicorp/vagrant@35f3160f4a (2026-08-21).
Data as JSON: /api/errors/e8af6b487b20a587.
Report an issue: GitHub.