-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNew-BCDStore.ps1
67 lines (58 loc) · 1.67 KB
/
New-BCDStore.ps1
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
function New-BCDStore
{
<#
.SYNOPSIS
Creates a Windows BCD-Store from Scratch.
.DESCRIPTION
Use New-BCDStore to create a new BCD-Store for Windows.
.EXAMPLE
New-BCDStore -bootdriveLetter c:
.NOTES
Author: Holger Voges
Version: 1.0.0
Date: 2017-09-23
#>
param
(
# Defines which Type of Start-Partition shall be created. If no Firmwaretype is set, the Firmwaretype
# will be determined automatically by the Host-Firmware
[String]
[Parameter()]
[ValidateSet('UEFI','BIOS')]
$FirmwareType,
[String]
[ValidatePattern('^([C-Zc-z]:?)$')]
$BootdriveLetter,
[int]
$BootmanagerTimeout = 30
)
If (-not $FirmwareType)
{
$FirmwareType = Get-BCDFirmWareType
}
$EfiBootmgrPath = '\efi\microsoft\boot'
If ( $BootdriveLetter.Length -eq 1 )
{
$BootdriveLetter += ':'
}
if (-not ( Test-Path $BootdriveLetter ))
{
Throw 'Das Bootlaufwerk konnte nicht gefunden werden'
}
bcdedit /createstore bcdTemplate
bcdedit /import bcdTemplate
Remove-Item bcdTemplate -Force
bcdedit /create '{bootmgr}'
bcdedit /set '{bootmgr}' device partition=$BootdriveLetter
bcdedit /timeout $BootmanagerTimeout
bcdedit /set '{bootmgr}' description "Windows Boot Manager"
If ( $FirmwareType -eq 'UEFI' )
{
bcdedit /set "{bootmgr}" path ('{0}\bootmgfw.efi' -f $EfiBootmgrPath)
Copy-Item -Path "$env:windir\boot\EFI\*" -Destination ( Join-Path -Path $BootdriveLetter -ChildPath $EfiBootmgrPath ) -Force
}
Else
{
Copy-Item -Path "$env:windir\boot\PCAT\*" -Destination ( Join-Path -path $BootdriveLetter -ChildPath \boot\ ) -Force
}
}