Created
February 11, 2016 18:52
-
-
Save devhawk/0fac19af5c038c6ed2c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| param([Parameter(Mandatory=$true)][string]$filename, [string]$displayname) | |
| $local:windowsIdentity = [System.Security.Principal.WindowsIdentity]::GetCurrent() | |
| $local:windowsPrincipal = new-object 'System.Security.Principal.WindowsPrincipal' $local:windowsIdentity | |
| if ($local:windowsPrincipal.IsInRole("Administrators") -ne 1) | |
| { | |
| throw "add-bcd-vhd must be run from an administrator account" | |
| } | |
| $f = resolve-path $filename | |
| if ([string]::IsNullOrEmpty($displayname)) | |
| { | |
| $displayname = [IO.Path]::GetFileNameWithoutExtension($f) | |
| } | |
| $vhdvalue = "[$($f.Drive.Name):]$($f.Path.Substring(2))" | |
| $rx = [regex] "\{\w{8}-\w{4}-\w{4}-\w{4}-\w{12}\}" | |
| $r = bcdedit /copy '{current}' /d $displayname | |
| $m = $rx.match($r) | |
| if ($m.success) | |
| { | |
| $guid = $m.value | |
| $ret = bcdedit /set $guid device vhd=$vhdvalue | |
| if ($ret -ne "the operation completed successfully.") | |
| { | |
| throw $ret | |
| } | |
| $ret = bcdedit /set $guid osdevice vhd=$vhdvalue | |
| if ($ret -ne "the operation completed successfully.") | |
| { | |
| throw $ret | |
| } | |
| $ret = bcdedit /set $guid detecthal on | |
| if ($ret -ne "the operation completed successfully.") | |
| { | |
| throw $ret | |
| } | |
| echo "$displayname ($(split-path -leaf $f)) VHD Boot Configured" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment