Skip to content

Commit

Permalink
Merge pull request #608 from microsoft/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
jaromirk authored Oct 29, 2024
2 parents 9ffe266 + 0d3358c commit f4a1cba
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
12 changes: 12 additions & 0 deletions Scripts/1_Prereq.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,18 @@ function Get-WindowsBuildNumber {

#endregion

#region Installing PSDesiredStateConfiguration from the PowerShell gallery

# See https://learn.microsoft.com/en-us/powershell/dsc/overview?view=dsc-2.0 for details
# on the breaking change that requires this module to be installed.
WriteInfoHighlighted "Testing if PSDesiredStateConfiguration is present"
if (!(Get-Module -ListAvailable -Name PSDesiredStateConfiguration)) {
WriteInfo "`t Module PSDesiredStateConfiguration not found... Downloading"
Install-Module -Name PSDesiredStateConfiguration -Repository PSGallery -MaximumVersion 2.99
}

#endregion

#region Downloading required Posh Modules
# Downloading modules into Temp folder if needed.

Expand Down
50 changes: 40 additions & 10 deletions Scripts/3_Deploy.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,11 @@ If (-not $isAdmin) {
WriteInfo "`t Creating OS VHD"
New-VHD -ParentPath $serverparent.fullname -Path $vhdpath

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

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

#Get VM Version
[System.Version]$VMVersion=(Get-WindowsImage -ImagePath $VHDPath -Index 1).Version
WriteInfo "`t VM Version is $($VMVersion.Build).$($VMVersion.Revision)"
[System.Version]$BuildVersion=(Get-WindowsImage -ImagePath $VHDPath -Index 1).Version
WriteInfo "`t VM Version is $($BuildVersion.Build).$($BuildVersion.Revision)"

WriteInfo "`t Creating VM"
if ($VMConfig.Generation -eq 1){
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 1
if ($VMConfig.VMVersion){
if ($VMConfig.Generation -eq 1){
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 1 -Version $VMConfig.VMVersion
}else{
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 2 -Version $VMConfig.VMVersion
}
}else{
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 2
if ($VMConfig.Generation -eq 1){
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 1
}else{
$VMTemp=New-VM -Name $VMname -VHDPath $vhdpath -MemoryStartupBytes $VMConfig.MemoryStartupBytes -path "$LabFolder\VMs" -SwitchName $SwitchName -Generation 2
}
}
$VMTemp | Set-VMMemory -DynamicMemoryEnabled $true
$VMTemp | Get-VMNetworkAdapter | Rename-VMNetworkAdapter -NewName Management1
Expand Down Expand Up @@ -742,7 +754,7 @@ If (-not $isAdmin) {
WriteInfo "`t`t No sync commands requested"
}

if ($VMVersion.Build -ge 17763){
if ($BuildVersion.Build -ge 17763){
$oeminformation=@"
<OEMInformation>
<SupportProvider>MSLab</SupportProvider>
Expand Down Expand Up @@ -1162,13 +1174,31 @@ If (-not $isAdmin) {

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

#Create Mount nd VMs directories
#Create Mount and VMs directories
WriteInfoHighlighted "Creating Mountdir"
New-Item $mountdir -ItemType Directory -Force

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

#unmount&cleanup mounted images
WriteInfoHighlighted "Unmounting images from previous run"
$MountedImages=Get-WindowsImage -Mounted | Where-Object MountStatus -ne "Invalid"
if ($MountedImages){
WriteInfo "`t Mounted images found, Dismounting, discarting"
$MountedImages | Dismount-WindowsImage -Discard -ErrorAction Ignore
}else{
WriteInfo "`t No mounted images found"
}
#cleanup corrupted
$InvalidImages=Get-WindowsImage -Mounted | Where-Object MountStatus -eq "Invalid"
if ($InvalidImages){
WriteInfo "`t Invalid mountpoints found, clearing"
Clear-WindowsCorruptMountPoint
}else{
WriteInfo "`t No invalid mountpoints found"
}

#get path for Tools disk
WriteInfoHighlighted "Looking for Tools Parent Disks"
$toolsparent=Get-ChildItem "$PSScriptRoot\ParentDisks" -Recurse | Where-Object name -eq tools.vhdx
Expand Down Expand Up @@ -1493,9 +1523,9 @@ If (-not $isAdmin) {
if(-not $VMConfig.configuration) {
$VMConfig.configuration = "Simple"
}
# Ensure that MemoryStartupBytes is set to use 512MB as default
# Ensure that MemoryStartupBytes is set to use 1GB as default
if(-not $VMConfig.MemoryStartupBytes) {
$VMConfig.MemoryStartupBytes = 512MB
$VMConfig.MemoryStartupBytes = 1GB
}

#create VM with Shared configuration
Expand Down
9 changes: 7 additions & 2 deletions Scripts/LabConfig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ $LabConfig=@{AllowedVLANs="1-10,711-719" ; DomainAdminName='LabAdmin'; AdminPass
# Windows Server 2022
1..4 | ForEach-Object {$LABConfig.VMs += @{ VMName = "$S2D$_" ; Configuration = 'S2D' ; ParentVHD = 'Win2022Core_G2.vhdx'; SSDNumber = 0; SSDSize=800GB ; HDDNumber = 12; HDDSize= 4TB ; MemoryStartupBytes= 512MB }}
# Or Azure Stack HCI 23H2 (non-domain joined) https://github.com/DellGEOS/AzureStackHOLs/tree/main/lab-guides/01a-DeployAzureStackHCICluster-CloudBasedDeployment
#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 }}
#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 }}
# Or Windows Server 2025 https://github.com/DellGEOS/AzureStackHOLs/tree/main/lab-guides/03-TestingWindowsServerInsider
#1..2 | ForEach-Object {$LABConfig.VMs += @{ VMName="S2D$_" ; Configuration='S2D' ; ParentVHD='WinSrvInsiderCore_26063.vhdx' ; HDDNumber=4 ; HDDSize=2TB ; MemoryStartupBytes=1GB; VMProcessorCount=4 ; vTPM=$true}}
#1..2 | ForEach-Object {$LABConfig.VMs += @{ VMName="S2D$_" ; Configuration='S2D' ; ParentVHD='Win2025Core_G2.vhdx' ; HDDNumber=4 ; HDDSize=2TB ; MemoryStartupBytes=1GB; VMProcessorCount=4 ; vTPM=$true}}

### HELP ###

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

Expand Down

0 comments on commit f4a1cba

Please sign in to comment.