I need to run these 4 commands to boot a new image into a device:
bcdedit /copy {current} /d "Describe"
bcdedit /set {guid} osdevice vhd=somepath
bcdedit /set {guid} device vhd=somepath
bcdedit /default {$guid}
To automate my script, I want to extract the guid/identifier returned as output from the first command and pass it as a parameter to the other 3 commands. Right now, I'm doing it in this way:
$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} "}
But, each time I get an error:
The element data type is not recognized, or does not apply to the specified entry. Run "bcdedit /?" for command line assistance. Element not found
This works fine when I manually copy and paste the path in the UI, but I'm not sure how I can automate it.