From 64f80e4f4ae114a63568e15e1f0ce5af54f2c4c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Mach?= Date: Fri, 15 Oct 2021 15:38:51 +0200 Subject: [PATCH] LabConfig option to specify additional network adapters. --- Scripts/3_Deploy.ps1 | 28 ++++++++++++++++++++++++++++ Scripts/LabConfig.ps1 | 13 ++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Scripts/3_Deploy.ps1 b/Scripts/3_Deploy.ps1 index b4de9168..31916a3d 100644 --- a/Scripts/3_Deploy.ps1 +++ b/Scripts/3_Deploy.ps1 @@ -474,6 +474,34 @@ If (-not $isAdmin) { $global:IP++ } + if($VMConfig.AdditionalNetworkAdapters) { + $networks = $VMConfig.AdditionalNetworkAdapters + if($networks -isnot [array]) { + $networks = @($networks) + } + + foreach ($network in $networks) { + $switch = Get-VMSwitch -Name $network.VirtualSwitchName -ErrorAction SilentlyContinue + if(-not $switch) { + WriteErrorAndExit "Hyper-V switch $($network.VirtualSwitchName) not found." + } + + $adapter = $vmtemp | Add-VMNetworkAdapter -SwitchName $network.VirtualSwitchName -Passthru + + if($network.Mac -and $network.Mac -match "^([0-9A-F][0-9A-F]-){5}[0-9A-F][0-9A-F]$") { + $adapter | Set-VMNetworkAdapter -StaticMacAddress $network.Mac + } + + if($network.VlanId -and $network.VlanId -ne 0) { + $adapter | Set-VMNetworkAdapterVlan -VlanId $network.VlanId -Access + } + + if($network.IpConfiguration -and $network.IpConfiguration -ne "DHCP" -and $network.IpConfiguration -is [Hashtable]) { + $adapter | Set-VMNetworkConfiguration -IPAddress $network.IpConfiguration.IpAddress -Subnet $network.IpConfiguration.Subnet + } + } + } + #Generate DSC Config if ($VMConfig.DSCMode -eq 'Pull'){ WriteInfo "`t Setting DSC Mode to Pull" diff --git a/Scripts/LabConfig.ps1 b/Scripts/LabConfig.ps1 index 1a31d27d..70290bfb 100644 --- a/Scripts/LabConfig.ps1 +++ b/Scripts/LabConfig.ps1 @@ -8,7 +8,6 @@ $LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!'; Prefix = 'M # Or Windows Server 2019 #1..4 | ForEach-Object {$VMNames="S2D"; $LABConfig.VMs += @{ VMName = "$VMNames$_" ; Configuration = 'S2D' ; ParentVHD = 'Win2019Core_G2.vhdx'; SSDNumber = 0; SSDSize=800GB ; HDDNumber = 12; HDDSize= 4TB ; MemoryStartupBytes= 512MB }} - ### HELP ### #If you need more help or different configuration options, ping us at jaromir.kaspar@dell.com or vlmach@microsoft.com @@ -220,6 +219,18 @@ $LabConfig=@{ DomainAdminName='LabAdmin'; AdminPassword='LS1setup!'; Prefix = 'M AdditionalNetworks (Optional) $True - Additional networks (configured in AdditonalNetworkConfig) are added + AdditionalNetworkAdapters (Optional) - Hashtable or array if multiple network adapters should be connected to this virtual machine + @{ + VirtualSwitchName (Mandatory) - Name of the Hyper-V Switch to witch the adapter will be connected + Mac (Optional) - Static MAC address of the interface otherwise default will be generated + VlanId (Optional) - VLAN ID for this adapter + IpConfiguration (Optional) - DHCP or hastable with specific IP configuration + @{ + IpAddress (Mandatory) - Static IP Address that would be injected to the OS + Subnet (Mandatory) + } + } + DSCMode (Optional) If 'Pull', VMs will be configured to Pull config from DC.