Question

Create managed network with PowerShell

  • 11 July 2019
  • 3 replies
  • 1064 views

Hi All

I've rather large number of non-managed and managed networks to create on multiple clusters and really am not willing to be creating them manually.

I've created PowerShell script to create non managed networks, that was pretty easy. However, I'm finding it a bit more challenging to create managed networks using PowerShell commandlets.

I understand that the command should look something like
New-NTNXNetwork -Name "vLAN_Name" -VlanId "vLAN_ID" -ipconfig "IpConfigDTO"

I can not find any samples of IpConfigDTO format. I understand that IPv4 default gateway address and subnet in CIDR notation should be provided as values but I can't work it out how.

Any assistance would be much appreciated.

Cheers

3 replies

Userlevel 2
Badge +2
@PrivIaaS Hi, I spent a considerable time trying to work this out!! (..as you say not much info out there!!) Still not quite sure this is the best way to achieve this, but it does work! I basically clone the existing VLAN 0 config and then populate the necessary to complete the task.

###################################################################
## Managed Nutanix Network Creation by @andymlloyd

## Use the Out of Box VLAN 0 CVM Network as a reference point for our new network

$managednetwork=Get-NTNXNetwork | where {$_.vlanid -eq 0}

## DHCP Options ##

$thenetworkdhcpoptionsobject=$managednetwork.ipConfig.dhcpOptions ## Create a DTO for DHCP Options using Reference
$thenetworkdhcpoptionsobject.domainName = "andytest.local"
$thenetworkdhcpoptionsobject.domainNameServers = "10.100.124.200"
$thenetworkdhcpoptionsobject.domainSearch = "andytest.local"

## IP Pool Options ##

$mypool=@()
$itemforpool=New-Object psobject
$itemforpool | Add-Member -MemberType NoteProperty -Name 'range' -Value '10.100.124.10 10.100.124.99'
$mypool+=$itemforpool
$managednetworkippool += $mypool

$managednetwork.ipConfig.pool = $managednetworkippool ## Set the IP Pool Options
$managednetwork.ipConfig.dhcpOptions = $thenetworkdhcpoptionsobject ## Set the DHCP Options

## Set the Core Information ##
## e.g. Name, VLAN Number, Annotation, Gateway, DHCP Server address, Subnet and Network Address
$managednetwork.name = "AndyLloyd124"
$managednetwork.vlanId="124"
$managednetwork.annotation= "AndyLloyd124"
$managednetwork.ipConfig.defaultGateway="10.100.124.1"
$managednetwork.ipConfig.dhcpServerAddress="10.100.124.254"
$managednetwork.ipConfig.prefixLength="24"
$managednetwork.ipConfig.networkAddress ="10.100.124.0"

## Now create the new Managed Network

New-NTNXNetwork -VlanId 124 -IpConfig $managednetwork.ipConfig -Name "AndyLloyd124" -Annotation "AndyLloyd124"

###################################################################

Hope this helps you out and anyone else who needs this functionality. If it does please mark as "Best Answer" 🙂

Regards
Userlevel 7
Badge +34
Hi @PrivIaaS - did the above help from @andymlloyd ?

If it helps, please consider clicking the 'like' and 'best answer' link as that will help others in the community find the answer much quicker - Thanks.
Hi Andymlloyd

Much appreciate your response. I'm currently away from office and won't be able to test this for couple of weeks or so. I certainly will do so when back and let you know how it goes.

Cheers

Reply