From 73c325d516f264ebf2d9c08627ae3392aa2ee828 Mon Sep 17 00:00:00 2001 From: Jaromir Kaspar Date: Wed, 3 Apr 2024 09:31:30 +0200 Subject: [PATCH 1/2] ManagementSubnetIDs removed --- Scripts/3_Deploy.ps1 | 85 +++---------------------------------------- Scripts/LabConfig.ps1 | 9 ----- 2 files changed, 5 insertions(+), 89 deletions(-) diff --git a/Scripts/3_Deploy.ps1 b/Scripts/3_Deploy.ps1 index e36aa092..5c4cc833 100644 --- a/Scripts/3_Deploy.ps1 +++ b/Scripts/3_Deploy.ps1 @@ -753,28 +753,9 @@ If (-not $isAdmin) { $oeminformation=$null } #configure native VLAN and AllowedVLANs - WriteInfo "`t Configuring NativeVLAN and AllowedVLANs" - if ($ManagementSubnetIDs){ - $number1=$(($HighestVLAN+1)) - $number2=$($HighestVLAN+$($ManagementSubnetIDs.Count)) - if ($number1 -eq $number2){ - $number=$number1 - }else{ - $number="$number1-$number2" - } - $AllowedVLANs="$($LabConfig.AllowedVLANs),$number" - }else{ $AllowedVLANs=$($LabConfig.AllowedVLANs) - } - - if ($VMConfig.ManagementSubnetID -gt 0){ - $NativeVlanId=($HighestVLAN+$VMConfig.ManagementSubnetID) - WriteInfo "`t`t Subnet ID is $($VMConfig.ManagementSubnetID) with NativeVLAN $NativeVLanID. AllowedVLANIDList is $($LabConfig.AllowedVLANs),$NativeVLANID" - $VMTemp | Set-VMNetworkAdapterVlan -VMNetworkAdapterName "Management*" -Trunk -NativeVlanId $NativeVlanId -AllowedVlanIdList "$AllowedVLANs" - }else{ WriteInfo "`t`t Subnet ID is 0 with NativeVLAN 0. AllowedVlanIDList is $($LabConfig.AllowedVLANs)" $VMTemp | Set-VMNetworkAdapterVlan -VMNetworkAdapterName "Management*" -Trunk -NativeVlanId 0 -AllowedVlanIdList "$AllowedVLANs" - } #Create Unattend file if ($VMConfig.Unattend -eq "NoDjoin" -or $VMConfig.SkipDjoin){ @@ -923,12 +904,6 @@ If (-not $isAdmin) { #Calculate highest VLAN (for additional subnets) [int]$HighestVLAN=$LabConfig.AllowedVLANs -split "," -split "-" | Select-Object -Last 1 - #Grab defined Management Subnet IDs and ignore 0 - $ManagementSubnetIDs=$labconfig.vms.ManagementSubnetID + $LabConfig.ManagementSubnetIDs | Select-Object -Unique | Sort-Object | Where-Object {$_ -ne 0} - if ($ManagementSubnetIDs){ - WriteInfo "`t Requested ManagementSubnetIDs: $ManagementSubnetIDs" - } - #endregion #region Some Additional checks and prereqs configuration @@ -1314,19 +1289,11 @@ If (-not $isAdmin) { $DC=get-vm -Name ($labconfig.prefix+"DC") } - #add addtional subnets if specified - if ($ManagementSubnetIDs){ - WriteInfo "`t Adding adapters for additional subnets" - foreach ($number in $ManagementSubnetIDs){ - if ($DC | Get-VMNetworkadapter -Name "Subnet$number" -ErrorAction Ignore){ - WriteInfo "`t`t Adapters Subnet$number already present" - }else{ - WriteInfo "`t`t Adding adapter Subnet$number and configuring Access VLANID $($HighestVLAN+$number)" - $DC | Add-VMNetworkAdapter -SwitchName $SwitchName -Name "Subnet$number" -DeviceNaming On - $DC | Set-VMNetworkAdapterVlan -VMNetworkAdapterName "Subnet$number" -Access -VlanId ($HighestVLAN+$number) - } - } - } + #add VLANs to DC + WriteInfo "`t Configuring VLANs on DC" + $AllowedVLANs=$($LabConfig.AllowedVLANs) + WriteInfo "`t`t Subnet ID is 0 with NativeVLAN 0. AllowedVlanIDList is $($LabConfig.AllowedVLANs)" + $DC | Set-VMNetworkAdapterVlan -VMNetworkAdapterName "Management*" -Trunk -NativeVlanId 0 -AllowedVlanIdList "$AllowedVLANs" #Start DC if it is not running if ($DC.State -ne "Running"){ @@ -1462,48 +1429,6 @@ If (-not $isAdmin) { } } - #configure NICs and routing if ManagementSubnetIDs are specified - if ($ManagementSubnetIDs){ - WriteInfoHighlighted "`t Configuring subnets in DC" - #configure static IPs on SubnetX adapters - Invoke-Command -VMGuid $DC.id -Credential $cred -ScriptBlock { - Foreach ($number in $using:ManagementSubnetIDs){ - $IP="10.0.$number.1" - $AdapterName="Subnet$Number" - $NetAdapterName=(Get-NetAdapterAdvancedProperty | Where-Object displayvalue -eq $AdapterName).Name - if (Get-NetIPAddress -InterfaceAlias $NetAdapterName -IPAddress $IP -ErrorAction Ignore){ - Write-Output "`t`t Subnet $AdapterName already configured" - }else{ - Write-Output "`t`t Configuring static IP address $IP on Adapter $NetAdapterName" - New-NetIPAddress -InterfaceAlias $NetAdapterName -IPAddress $IP -PrefixLength 24 - #add dhcp scope - Write-Output "`t`t Adding DHCP Scope ID 10.0.$number.0 and it's DHCP options" - Add-DhcpServerv4Scope -StartRange "10.0.$number.10" -EndRange "10.0.$number.254" -Name "Scope$number" -State Active -SubnetMask 255.255.255.0 - } - } - #make sure RRAS features are installed - Write-Output "`t`t Making sure routing features are installed" - Install-WindowsFeature -Name Routing,RSAT-RemoteAccess -IncludeAllSubFeature -WarningAction Ignore - #enable routing - Write-Output "`t`t Making sure routing is enabled" - $routingEnabled = (Get-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters -Name IPEnableRouter).IPEnableRouter - if ($routingEnabled -match "0") { - New-ItemProperty HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters -Name IPEnableRouter -value 1 -Force - } - #restart routing... just to make sure - Write-Output "`t`t Restarting service RemoteAccess" - Restart-Service RemoteAccess - - #configure DHCP Options - Foreach ($number in $using:ManagementSubnetIDs){ - Set-DhcpServerv4OptionValue -OptionId 6 -Value "10.0.$number.1" -ScopeId "10.0.$number.0" - Set-DhcpServerv4OptionValue -OptionId 3 -Value "10.0.$number.1" -ScopeId "10.0.$number.0" - Set-DhcpServerv4OptionValue -OptionId 15 -Value "$($using:Labconfig.DomainName)" -ScopeId "10.0.$number.0" - } - } - } - - #endregion #region Provision VMs diff --git a/Scripts/LabConfig.ps1 b/Scripts/LabConfig.ps1 index dfa3efaa..8adbb3a9 100644 --- a/Scripts/LabConfig.ps1 +++ b/Scripts/LabConfig.ps1 @@ -42,7 +42,6 @@ $LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!'; Prefix = 'M TelemetryNickname=""; # (Optional) If configured, telemetry will be sent with NickName to correlate data to specified NickName. So when leaderboards will be published, MSLab users will be able to see their own stats AutoStartAfterDeploy=$false; # (Optional) If $false, no VM will be started; if $true or 'All' all lab VMs will be started after Deploy script; if 'DeployedOnly' only newly created VMs will be started. InternetVLAN=""; # (Optional) If set, it will apply VLAN on Interent adapter connected to DC - ManagementSubnetIDs=""; # (Optional) If set, it will add another dhcp-enable management networks. Linux=$false; # (Optional) If set to $true, required prerequisities for building Linux images with Packer will be configured. LinuxAdminName="linuxadmin"; # (Optional) If set, local user account with that name will be created in Linux image. If not, DomainAdminName will be used as a local account. SshKeyPath="$($env:USERPROFILE)\.ssh\id_rsa" # (Optional) If set, specified SSH key will be used to build and access Linux images. @@ -193,10 +192,6 @@ $LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!'; Prefix = 'M Example: TelemetryNickname="Jaromirk" If configured, telemetry will be sent with NickName to correlate data to specified NickName. So when leaderboards will be published, MSLab users will be able to see their own stats - ManagementSubnetIDs - Example: ManagementSubnetIDs=0..3 - If configured, it will add another management subnet. For example if configured 0..3, it will add 3 more subnets 10.0.1.0/24 to 10.0.3.0/24 on VLANs that 11,12, and 13. (Because allowed VLANs are 1-10) - Linux (optional) Example: Linux=$true If set to $true, additional prerequisities (SSH Client, SSH Key, Packer, Packer templates) required for building Linux images will be downloaded and configured. @@ -342,10 +337,6 @@ $LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!'; Prefix = 'M Example (single command) CustomPowerShellCommands="New-Item -Name Temp -Path c:\ -ItemType Directory" Example (multiple commands) CustomPowerShellCommands="New-Item -Name Temp -Path c:\ -ItemType Directory","New-Item -Name Temp1 -Path c:\ -ItemType Directory" - ManagementSubnetID (Optional) - This will set Management NICs to defined subnet id by configuring native VLAN ID. Default is 0. If configured to 1, it will increase highest allowed VLAN by one and configure. - For example ManagementSubnetID=1, AllowedVlans=10, then ManagementSubnetID VLAN will be configured 11. - #DisableTimeIC (Optional) Example DisableTimeIC=$true if $true, time Hyper-V Time Synchronization Integration Service (VMICTimeProvider) will be disabled From 682f576c0a3f16edcccb7da24b05365ab2bded31 Mon Sep 17 00:00:00 2001 From: Jaromir Kaspar Date: Wed, 3 Apr 2024 10:00:15 +0200 Subject: [PATCH 2/2] typo --- Scripts/3_Deploy.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/3_Deploy.ps1 b/Scripts/3_Deploy.ps1 index 5c4cc833..dfef20eb 100644 --- a/Scripts/3_Deploy.ps1 +++ b/Scripts/3_Deploy.ps1 @@ -1729,7 +1729,7 @@ If (-not $isAdmin) { $telemetryEvent = Initialize-TelemetryEvent -Event "Deploy.End" -Metrics $metrics -Properties $properties -NickName $LabConfig.TelemetryNickName $vmDeploymentEvents += $telemetryEvent - Send-TelemetryEvent -Events $vmDeploymentEvents | Out-Null + Send-TelemetryEvents -Events $vmDeploymentEvents | Out-Null } #write how much it took to deploy