Op zich doet dit script niet zo heel veel
- Ga na of de iso file bestaat
- vind de E: partitie, welke op al onze laptops de laatste en grootste partitie hoort te zijn
- maak deze wat kleiner (het script dat dit script aanroept controleert of er voldoende ruimte is)
- maak een nieuwe partitie aan in de vrijgekomen ruimte
- kopieer de inhoud van de ISO naar de nieuwe partie
- pas de bootloader aan
- pauzeer bitlocker op de E: schijf, deze gaan we niet wissen en als we bitlocker niet tijdig stopxetten hebben we na de herinstall een gelockte schijf zonder sleutel (al zit de recovery key nog in AD)
code:
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
| param (
$isoFile = ".\LiteTouchMedia.iso"
)
# checking prerequisits
if (-not (Test-Path -Path "$isoFile")) {
Throw "ISO file not found at $($isoFile)"
}
# On both light and full builds, the E-partition is the last partition
# created on the drive by the old build process. The G partition
# is placed before the E partition. So we want to shrink the E partition
# if possible and use that space to create a new, temporary partition.
Write-Output "Searching for the right partition"
$partitions = Get-Partition -DiskNumber 0 | Where-Object {$_.Type -eq "Basic"}
$partitionId = 0
foreach ($partition in $partitions) {
if ($partition.DriveLetter -eq "E") {
$partitionId = $Partition.PartitionNumber
Write-Output "Found drive E with partition number $partitionId"
}
}
if ($partitionId -eq 0) {
Throw "Unable to find a partition with driveletter E, is this a properly deployed build?"
}
Write-Output "Checking if we have enough free disk space"
$requiredFreeSpace = 10737418240
$volume = Get-Volume -DriveLetter E
if ($volume.SizeRemaining -lt $requiredFreeSpace) {
Throw "Less than 10GiB available on E, not enough space to extract image"
}
Write-Output "Checking if we the drive letter T is available"
if (-not $(Get-PSDrive -Name T -ErrorAction SilentlyContinue)) {
$newPartitionLetter = "T"
}
if ($null -eq $newPartitionLetter) {
Throw "Driveletter T is in use, is this a properly deployed build?"
}
Write-Output "Attempting to resize partition E"
try {
Resize-Partition -DiskNumber 0 -PartitionNumber $partitionId -Size $($Volume.Size - $requiredFreeSpace)
}
catch {
Throw "Unable to resize partition"
}
Write-Output "Creating new partition"
try {
New-Partition -DiskNumber 0 -UseMaximumSize -DriveLetter "T"
}
catch {
Throw "Unable to create new partition"
}
Write-Output "Formatting new volume T"
Format-Volume -DriveLetter T
Write-Output "Extracting ISO file"
$DiskImage = Mount-DiskImage -ImagePath "$isoFile" -StorageType ISO -NoDriveLetter -PassThru
New-PSDrive -Name ISOFile -PSProvider FileSystem -Root (Get-Volume -DiskImage $DiskImage).UniqueId
Push-Location ISOFile:
# we use copy-item as robocopy does not like our current location
Copy-Item .\* T:\ -Recurse
Pop-Location
Remove-PSDrive ISOFile
Dismount-DiskImage -DevicePath $DiskImage.DevicePath
Write-Output "Modifying boot loader"
Write-Output "- creating RAM disk options"
bcdedit /create "{ramdiskoptions}" /d "Ramdisk"
bcdedit /set "{ramdiskoptions}" ramdisksdidevice partition=T:
bcdedit /set "{ramdiskoptions}" ramdisksdipath \boot\boot.sdi
Write-Output "- creating new bootloader entry"
$copy = bcdedit -create /d "Upgrade" -application osloader
$bootId = $copy.Substring($copy.IndexOf("{")+1)
$bootId = $bootId.Substring(0,$bootId.IndexOf("}"))
Write-Output "- new entry created with GUID $bootId"
Write-Output "- setting device"
bcdedit /set "{$bootId}" device "ramdisk=[T:]\Deploy\boot\LiteTouchPE_x64.wim,{ramdiskoptions}"
Write-Output "- setting path"
bcdedit /set "{$bootId}" path \windows\system32\winload.efi
Write-Output "- setting OS device"
bcdedit /set "{$bootId}" osdevice "ramdisk=[T:]\Deploy\boot\LiteTouchPE_x64.wim,{ramdiskoptions}"
Write-Output "- setting system root"
bcdedit /set "{$bootId}" systemroot \windows
Write-Output "- setting winpe"
bcdedit /set "{$bootId}" winpe yes
Write-Output "- setting HAL detection"
bcdedit /set "{$bootId}" detecthal yes
Write-Output "- setting $bootId as standard boot entry"
bcdedit /bootsequence "{$bootId}"
Write-Output "Suspending bitlocker on E:"
Suspend-Bitlocker E: |
No keyboard detected. Press F1 to continue.