arynhard
arynhard

Reputation: 473

Powershell command line argument with spaces and curly brackets?

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:

Upvotes: 5

Views: 5624

Answers (2)

arynhard
arynhard

Reputation: 473

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

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

Upvotes: 5

Tumba
Tumba

Reputation: 73

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.

Upvotes: 2

Related Questions