I'm trying to use powershell to commit a Windows BCD change. That BCDEDIT change line looks like this if run from a regular command line:
bcdedit /set {default} recoveryenabled No
BCDEDIT requires being run as an admin, so i've got a powershell script that's called from a scheduled task, and the script itself is really simple, as follows:
invoke-command -scriptblock {start-process -Verb RunAS bcdedit /set {default} recoveryenabled No}
However, when i run that, i get the following:
Invoke-Command : Parameter set cannot be resolved using the specified named
parameters. At line:1 char:1
+ invoke-command "bcdedit /set {default} recoveryenabled No"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Invoke-Command], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,Microsoft.PowerShell.Commands.InvokeCommandCommand
I'm assuming i need to wrap the {default} command somehow because it's already in a { } via the -scriptblock section - how would I proceed?
I probably could just use a plain-ol' DOS cmd script, but i want to use PowerShell as I like the logging features/etc and i'm performing other functions with the same script.
Owen
I changed the code into these and it worked.
Invoke-Command -ScriptBlock {Start-Process bcdedit -Verb RunAS -ArgumentList "/set {default} recoveryenabled NO"}
The bunch of things after bcdedit
, /set {default} recoveryenabled No
are actually bcdedit
's parameters. You have to start the process of bcdedit
and pass the rest of the things as its parameter.