我正在尝试编写我的第一个PowerShell脚本,但在运行以下代码时出现了错误。如何在PowerShell中传递参数给命令?
& "bcdedit" /store c:\boot\bcd /set {bootmgr} device partition=C:
编辑: 这段代码的有效版本如下:
& "bcdedit" /store c:\boot\bcd /set "{bootmgr}" device partition=C:
我正在尝试编写我的第一个PowerShell脚本,但在运行以下代码时出现了错误。如何在PowerShell中传递参数给命令?
& "bcdedit" /store c:\boot\bcd /set {bootmgr} device partition=C:
编辑: 这段代码的有效版本如下:
& "bcdedit" /store c:\boot\bcd /set "{bootmgr}" device partition=C:
{bootmgr}
周围加上引号可以解决问题。& "bcdedit" /store c:\boot\bcd /set "{bootmgr}" device partition=C:
cmd.exe /c 'bcdedit /store c:\boot\bcd /set {bootmgr} device partition=C:'
当你使用的命令需要带有字符串引号参数时,这种方法尤其有用。