Skip to content

Commit f4a1cba

Browse files
authored
Merge pull request #608 from microsoft/dev
Dev
2 parents 9ffe266 + 0d3358c commit f4a1cba

File tree

3 files changed

+59
-12
lines changed

3 files changed

+59
-12
lines changed

Scripts/1_Prereq.ps1

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,18 @@ function Get-WindowsBuildNumber {
192192

193193
#endregion
194194

195+
#region Installing PSDesiredStateConfiguration from the PowerShell gallery
196+
197+
# See https://learn.microsoft.com/en-us/powershell/dsc/overview?view=dsc-2.0 for details
198+
# on the breaking change that requires this module to be installed.
199+
WriteInfoHighlighted "Testing if PSDesiredStateConfiguration is present"
200+
if (!(Get-Module -ListAvailable -Name PSDesiredStateConfiguration)) {
201+
WriteInfo "`t Module PSDesiredStateConfiguration not found... Downloading"
202+
Install-Module -Name PSDesiredStateConfiguration -Repository PSGallery -MaximumVersion 2.99
203+
}
204+
205+
#endregion
206+
195207
#region Downloading required Posh Modules
196208
# Downloading modules into Temp folder if needed.
197209

Scripts/3_Deploy.ps1

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,11 @@ If (-not $isAdmin) {
424424
WriteInfo "`t Creating OS VHD"
425425
New-VHD -ParentPath $serverparent.fullname -Path $vhdpath
426426

427-
$VMTemp = New-VM -Path "$LabFolder\VMs" -Name $VMname -Generation 2 -MemoryStartupBytes $VMConfig.MemoryStartupBytes -SwitchName $SwitchName -VHDPath $vhdPath
427+
if ($VMConfig.VMVersion){
428+
$VMTemp = New-VM -Path "$LabFolder\VMs" -Name $VMname -Generation 2 -MemoryStartupBytes $VMConfig.MemoryStartupBytes -SwitchName $SwitchName -VHDPath $vhdPath -Version $VMConfig.VMVersion
429+
}else{
430+
$VMTemp = New-VM -Path "$LabFolder\VMs" -Name $VMname -Generation 2 -MemoryStartupBytes $VMConfig.MemoryStartupBytes -SwitchName $SwitchName -VHDPath $vhdPath
431+
}
428432

429433
#Set dynamic memory
430434
if ($VMConfig.StaticMemory -eq $false){
@@ -547,14 +551,22 @@ If (-not $isAdmin) {
547551
New-VHD -ParentPath $serverparent.fullname -Path $vhdpath
548552

549553
#Get VM Version
550-
[System.Version]$VMVersion=(Get-WindowsImage -ImagePath $VHDPath -Index 1).Version
551-
WriteInfo "`t VM Version is $($VMVersion.Build).$($VMVersion.Revision)"
554+
[System.Version]$BuildVersion=(Get-WindowsImage -ImagePath $VHDPath -Index 1).Version
555+
WriteInfo "`t VM Version is $($BuildVersion.Build).$($BuildVersion.Revision)"
552556

553557
WriteInfo "`t Creating VM"
554-
if ($VMConfig.Generation -eq 1){
555-
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 1
558+
if ($VMConfig.VMVersion){
559+
if ($VMConfig.Generation -eq 1){
560+
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 1 -Version $VMConfig.VMVersion
561+
}else{
562+
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 2 -Version $VMConfig.VMVersion
563+
}
556564
}else{
557-
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 2
565+
if ($VMConfig.Generation -eq 1){
566+
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 1
567+
}else{
568+
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 2
569+
}
558570
}
559571
$VMTemp | Set-VMMemory -DynamicMemoryEnabled $true
560572
$VMTemp | Get-VMNetworkAdapter | Rename-VMNetworkAdapter -NewName Management1
@@ -742,7 +754,7 @@ If (-not $isAdmin) {
742754
WriteInfo "`t`t No sync commands requested"
743755
}
744756

745-
if ($VMVersion.Build -ge 17763){
757+
if ($BuildVersion.Build -ge 17763){
746758
$oeminformation=@"
747759
<OEMInformation>
748760
<SupportProvider>MSLab</SupportProvider>
@@ -1162,13 +1174,31 @@ If (-not $isAdmin) {
11621174

11631175
WriteInfo "`t Starting IP for AdditionalNetworks is $global:IP"
11641176

1165-
#Create Mount nd VMs directories
1177+
#Create Mount and VMs directories
11661178
WriteInfoHighlighted "Creating Mountdir"
11671179
New-Item $mountdir -ItemType Directory -Force
11681180

11691181
WriteInfoHighlighted "Creating VMs dir"
11701182
New-Item "$PSScriptRoot\LAB\VMs" -ItemType Directory -Force
11711183

1184+
#unmount&cleanup mounted images
1185+
WriteInfoHighlighted "Unmounting images from previous run"
1186+
$MountedImages=Get-WindowsImage -Mounted | Where-Object MountStatus -ne "Invalid"
1187+
if ($MountedImages){
1188+
WriteInfo "`t Mounted images found, Dismounting, discarting"
1189+
$MountedImages | Dismount-WindowsImage -Discard -ErrorAction Ignore
1190+
}else{
1191+
WriteInfo "`t No mounted images found"
1192+
}
1193+
#cleanup corrupted
1194+
$InvalidImages=Get-WindowsImage -Mounted | Where-Object MountStatus -eq "Invalid"
1195+
if ($InvalidImages){
1196+
WriteInfo "`t Invalid mountpoints found, clearing"
1197+
Clear-WindowsCorruptMountPoint
1198+
}else{
1199+
WriteInfo "`t No invalid mountpoints found"
1200+
}
1201+
11721202
#get path for Tools disk
11731203
WriteInfoHighlighted "Looking for Tools Parent Disks"
11741204
$toolsparent=Get-ChildItem "$PSScriptRoot\ParentDisks" -Recurse | Where-Object name -eq tools.vhdx
@@ -1493,9 +1523,9 @@ If (-not $isAdmin) {
14931523
if(-not $VMConfig.configuration) {
14941524
$VMConfig.configuration = "Simple"
14951525
}
1496-
# Ensure that MemoryStartupBytes is set to use 512MB as default
1526+
# Ensure that MemoryStartupBytes is set to use 1GB as default
14971527
if(-not $VMConfig.MemoryStartupBytes) {
1498-
$VMConfig.MemoryStartupBytes = 512MB
1528+
$VMConfig.MemoryStartupBytes = 1GB
14991529
}
15001530

15011531
#create VM with Shared configuration

Scripts/LabConfig.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ $LabConfig=@{AllowedVLANs="1-10,711-719" ; DomainAdminName='LabAdmin'; AdminPass
44
# Windows Server 2022
55
1..4 | ForEach-Object {$LABConfig.VMs += @{ VMName = "$S2D$_" ; Configuration = 'S2D' ; ParentVHD = 'Win2022Core_G2.vhdx'; SSDNumber = 0; SSDSize=800GB ; HDDNumber = 12; HDDSize= 4TB ; MemoryStartupBytes= 512MB }}
66
# Or Azure Stack HCI 23H2 (non-domain joined) https://github.com/DellGEOS/AzureStackHOLs/tree/main/lab-guides/01a-DeployAzureStackHCICluster-CloudBasedDeployment
7-
#1..2 | ForEach-Object {$LABConfig.VMs += @{ VMName = "ASNode$_" ; Configuration = 'S2D' ; ParentVHD = 'AzSHCI23H2_G2.vhdx' ; HDDNumber = 4 ; HDDSize= 2TB ; MemoryStartupBytes= 20GB; VMProcessorCount=16 ; vTPM=$true ; Unattend="NoDjoin" ; NestedVirt=$true }}
7+
#1..2 | ForEach-Object {$LABConfig.VMs += @{ VMName = "ASNode$_" ; Configuration = 'S2D' ; ParentVHD = 'AzSHCI23H2_G2.vhdx' ; HDDNumber = 4 ; HDDSize= 2TB ; MemoryStartupBytes= 24GB; VMProcessorCount=16 ; vTPM=$true ; Unattend="NoDjoin" ; NestedVirt=$true }}
88
# Or Windows Server 2025 https://github.com/DellGEOS/AzureStackHOLs/tree/main/lab-guides/03-TestingWindowsServerInsider
9-
#1..2 | ForEach-Object {$LABConfig.VMs += @{ VMName="S2D$_" ; Configuration='S2D' ; ParentVHD='WinSrvInsiderCore_26063.vhdx' ; HDDNumber=4 ; HDDSize=2TB ; MemoryStartupBytes=1GB; VMProcessorCount=4 ; vTPM=$true}}
9+
#1..2 | ForEach-Object {$LABConfig.VMs += @{ VMName="S2D$_" ; Configuration='S2D' ; ParentVHD='Win2025Core_G2.vhdx' ; HDDNumber=4 ; HDDSize=2TB ; MemoryStartupBytes=1GB; VMProcessorCount=4 ; vTPM=$true}}
1010

1111
### HELP ###
1212

@@ -340,6 +340,11 @@ $LabConfig=@{AllowedVLANs="1-10,711-719" ; DomainAdminName='LabAdmin'; AdminPass
340340
#DisableTimeIC (Optional)
341341
Example DisableTimeIC=$true
342342
if $true, time Hyper-V Time Synchronization Integration Service (VMICTimeProvider) will be disabled
343+
344+
#VMVersion (Optional)
345+
Example VMVersion="10.0"
346+
default versions - Windows Server 2022 = 10.0, Widnows Server 2025 = 12.0
347+
https://learn.microsoft.com/en-us/windows-server/virtualization/hyper-v/deploy/Upgrade-virtual-machine-version-in-Hyper-V-on-Windows-or-Windows-Server
343348
#>
344349
#endregion
345350

0 commit comments

Comments
 (0)