forked from Azure/AzureStack-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBootMenuNoKVM.ps1
More file actions
71 lines (60 loc) · 2.56 KB
/
BootMenuNoKVM.ps1
File metadata and controls
71 lines (60 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (c) Microsoft Corporation. All rights reserved.
# See LICENSE.txt in the project root for license information.
<#
.SYNOPSIS
Modify the boot entry and reboot the Azure Stack TP2 host back to the base Operating System, so that Azure Stack TP2 can be redeployed.
.DESCRIPTION
BootMenuNoKVM updates the boot configuration with the original entry, and then prompts to reboot the host.
Because the default boot entry is set with this script, no KVM or manual selection of the boot entry is required as the machine restarts.
.EXAMPLE
Prompt user for the desired boot configuraiton and confirm reboot of the host so a redeployment of Azure Stack TP2 can begin.
This does not require KVM access to the host for selection of the correct Operating System as the machine restarts.
.\BootMenuNoKVM.ps1
.NOTES
You will need execute this script in an elevated PS console session.
#>
#requires -version 4.0
#requires –runasadministrator
#region Menu
$prompt = ('Are you sure you want to configure this onetime boot value and reboot now?' + $title)
$Yes = New-Object System.Management.Automation.Host.ChoiceDescription '&Yes','Reboot now'
$Abort = New-Object System.Management.Automation.Host.ChoiceDescription '&Abort','Abort'
$options = [System.Management.Automation.Host.ChoiceDescription[]] ($Yes,$Abort)
#endregion
$bootOptions = bcdedit /enum | Select-String 'path' -Context 2,1
cls
#region Selection
write-host 'This script specifies a one-time display order to be used for the next boot. Afterwards, the computer reverts to the original display order.' -ForegroundColor Yellow
write-host 'Select the Operating System to boot from:' -ForegroundColor Cyan
$menu = @{}
for ($i=1;$i -le $bootOptions.count; $i++) {
Write-Host "$i. $($bootOptions[$i-1].Context.PostContext[0] -replace '^description +')"
$menu.Add($i,($bootOptions[$i-1].Context.PreContext[0]))
}
[int]$ans = Read-Host 'Enter selection'
$selection = $menu.Item($ans)
#endregion
$BootEntry = $selection -replace '^identifier +'
if($Selection -ne $null)
{
$choice = $host.ui.PromptForChoice($title,$prompt,$options,0)
if ($choice -eq 0)
{
$BootID = '"' + $BootEntry + '"'
bcdedit /bootsequence $BootID
Restart-Computer
}
else
{
write-host 'No changes are made to the boot configuration. Exiting..' -ForegroundColor Yellow
Break
}
}
else
{write-host 'Not a valid selection. No changes are made to the boot configuration. Exiting..' -ForegroundColor Yellow}