我需要运行这 4 个命令来将新映像引导到设备中:
bcdedit /copy {current} /d "Describe"
bcdedit /set {guid} osdevice vhd=somepath
bcdedit /set {guid} device vhd=somepath
bcdedit /default {$guid}
为了自动化我的脚本,我想提取作为第一个命令的输出返回的 guid/标识符,并将其作为参数传递给其他 3 个命令。现在,我正在这样做:
$guid = Invoke-Command -ComputerName $comp -Credential $cred -ScriptBlock {cmd /c "bcdedit /copy {current} /d "Describe""}
#output
#$guid = This entry was successfully copied to {xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}
$guid = $guid.Replace("This entry was successfully copied to {","")
$guid = $guid.Replace("}","")
$path1 = "xxx/xxxx/...."
#passing the guid and path as inputs
Invoke-Command -ComputerName $comp -Credential $cred -ScriptBlock {cmd /c "bcdedit /set {$guid} osdevice vhd=$path1"}
Invoke-Command -ComputerName $comp -Credential $cred -ScriptBlock {cmd /c "bcdedit /set {$guid} device vhd=$path1"}
Invoke-Command -ComputerName $comp -Credential $cred -ScriptBlock {cmd /c "bcdedit /default {$guid} "}
但是,每次我得到一个错误:
元素数据类型无法识别,或不适用于指定条目。运行“bcdedit /?” 用于命令行帮助。未找到元素
当我在 UI 中手动复制和粘贴路径时,这很好用,但我不确定如何自动化它。