PowerShell script exchange
Post Reply
dcop
Service Provider
Posts: 4
Liked: never
Joined: May 06, 2022 9:51 am
Full Name: datacenteroperations
Contact:

Virtual Lab add a second vNIC & "Isolated Network"

Post by dcop »

Hello, we have a powershell script that we can use to create a virtual lab with all the needed settings.
But now I am not able to add a second "Isolated Network" and/or a second vNIC2 in the "Network Settings" via the Powershell Script.
Manually via the console it goes smoothly, but I would like to incorporate this into the script. I tried it like this:

Code: Select all

$lab                         =   Get-VBRViVirtualLabConfiguration -Name $labname 
$esx                         =   Get-VBRServer -Name "$hostname.$env:USERDNSDOMAIN" 
$maskedIP2		=   "10.0.0.0" 
$ipv2                        =   "10.0.0.1"
$subnetmaskv2         =   "255.255.0.0"
$maskedIP2              =   "172.16.0.0" 
$IsolatedNetworkName2 = "$appliance_name2$networkname2" 
$networkname2       =   "smcc_TEST_460" 
$vlanid                    =   "999" 

$network2                =   Get-VBRViServerNetworkInfo -Server $esx | Where-Object { $_.NetworkName -eq $networkname2 } 
$maprule2                =   New-VBRViNetworkMappingRule -Server $esx -ProductionNetwork $network2 -IsolatedNetworkName $IsolatedNetworkName2 -VLANID $vlanid 
$NetworkOption2      =   New-VBRViVirtualLabNetworkOptions -NetworkMappingRule $maprule2 -IPAddress $ipv2 -SubnetMask $subnetmaskv2 -MasqueradeIPAddress $maskedIP2

Set-VBRVIVirtualLab -VirtualLab $lab -Type Advanced -NetworkOptions $NetworkOption2 
Thank you for any ideas or suggestions.
Kind regards, Dany Ambühl.
oleg.feoktistov
Veeam Software
Posts: 1918
Liked: 636 times
Joined: Sep 25, 2019 10:32 am
Full Name: Oleg Feoktistov
Contact:

Re: Virtual Lab add a second vNIC & "Isolated Network"

Post by oleg.feoktistov »

Hi,

Please note that Set-VBRViVirtualLab cmdlet (like any other Set cmdlet we have) just takes a specification you passed and
applies it to the object you choose, overwriting any existing option that falls into a specification scope.
So if you want to append, not overwrite, you need to create a new network options array that contains existing and new options together, then set this array for a lab. For example:

Code: Select all

$lab                         =   Get-VBRViVirtualLabConfiguration -Name $labname 
$networkOption        = $lab.NetworkOptions
$esx                         =   Get-VBRServer -Name "$hostname.$env:USERDNSDOMAIN" 
$maskedIP2		=   "10.0.0.0" 
$ipv2                        =   "10.0.0.1"
$subnetmaskv2         =   "255.255.0.0"
$maskedIP2              =   "172.16.0.0" 
$IsolatedNetworkName2 = "$appliance_name2$networkname2" 
$networkname2       =   "smcc_TEST_460" 
$vlanid                    =   "999" 
$network2                =   Get-VBRViServerNetworkInfo -Server $esx | Where-Object { $_.NetworkName -eq $networkname2 } 
$maprule2                =   New-VBRViNetworkMappingRule -Server $esx -ProductionNetwork $network2 -IsolatedNetworkName $IsolatedNetworkName2 -VLANID $vlanid 
$NetworkOption2      =   New-VBRViVirtualLabNetworkOptions -NetworkMappingRule $maprule2 -IPAddress $ipv2 -SubnetMask $subnetmaskv2 -MasqueradeIPAddress $maskedIP2
$networkArray = @()
$networkArray += $networkOption, $NetworkOption2

Set-VBRVIVirtualLab -VirtualLab $lab -Type Advanced -NetworkOptions $networkArray
Best regards,
Oleg
dcop
Service Provider
Posts: 4
Liked: never
Joined: May 06, 2022 9:51 am
Full Name: datacenteroperations
Contact:

Re: Virtual Lab add a second vNIC & "Isolated Network"

Post by dcop »

Hi Oleg
Thx for the fast response.

With the Arrays its working now:

#Array definieren for maprule
$mapruleArray = @()
$mapruleArray = $maprule, $maprule2

#Array definieren
$networkArray = @()
$networkArray = $NetworkOption, $NetworkOption2

Add-VBRViAdvancedVirtualLab -Server $esx -Name $labname -Description $vlabdescripton -DesignatedResourcePoolName $respool -DesignatedVMFolderName $vmfolder -CacheDatastore $cachedatastore -ProxyAppliance $ProxyAppliance -NetworkMappingRule $mapruleArray -NetworkOptions $networkArray -EnableRoutingBetweenvNics -Force


Regards Dany
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests