5

I am making an attempt at my first powershell script and getting a bad parameter error when running the following code. How can I pass the argument to the command in powersehll?

& "bcdedit" /store c:\boot\bcd /set {bootmgr} device partition=C:

EDIT: The working code for this is:

& "bcdedit" /store c:\boot\bcd /set "{bootmgr}" device partition=C:
arynhard
  • 473
  • 2
  • 8
  • 26

2 Answers2

5

The curly brackets threw everything off. Putting quotes around {bootmgr} fixed the problem.

& "bcdedit" /store c:\boot\bcd /set "{bootmgr}" device partition=C:
arynhard
  • 473
  • 2
  • 8
  • 26
2

The problem you are running into is that the PowerShell parser works differently than the cmd.exe parser does. One way around this is to pass your command to cmd.exe and let it do the parsing.

To do this, pass the command to cmd.exe using the /c option as a single-quoted string.

cmd.exe /c 'bcdedit /store c:\boot\bcd /set {bootmgr} device partition=C:'

This method is especially useful when the command you are using requires string-quoted arguments.

Tumba
  • 73
  • 1
  • 5
  • This is a great solution for so many issues with Powershell (especially if you are already invested in the old command line) – Froyke Apr 26 '13 at 00:03