SCVMM – Creating VM Networks and Logical Networks using PowerShell

This week at a customer site, a tragic accident with a Live Storage Migration forced me to rebuild most of my recently build System Center environment. Luckily, I had created some scripts to automate tasks. One of which particularly saved a lot of typing. The customer will have multiple clouds and wants to limit to which VLANs the Cloud Users will be able to deploy to.

The way the environment works allowed me to have a simple script with Three configurable parameters:

$LogicalNetworkName=”Network Name”

A few standards made things easier:

  • The customer will have basically two groups of clusters.
  • The last octet is the VLANID
  • The description is also the VLAN ID

Once the rest of the scripts runs, it will create the Logical network, assign it to the Host Group, create a VM Network with the same name and description:

$LogicalNetworkDescription=”VLAN $LogicalNetworkSubnetVLANID”

$logicalNetwork = New-SCLogicalNetwork -Name $LogicalNetworkName -LogicalNetworkDefinitionIsolation $false -EnableNetworkVirtualization $false -UseGRE $false -IsPVLAN $false -Description $LogicalNetworkDescription

$allHostGroups = @()
$allHostGroups += Get-SCVMHostGroup -Name $HostGroupName
$allSubnetVlan = @()
$allSubnetVlan += New-SCSubnetVLan -Subnet $LogicalNetworkSubnet -VLanID $LogicalNetworkSubnetVLANID

New-SCLogicalNetworkDefinition -Name $LogicalNetworkSubnetName -LogicalNetwork $logicalNetwork -VMHostGroup $allHostGroups -SubnetVLan $allSubnetVlan -RunAsynchronously

$logicalNetwork = Get-SCLogicalNetwork -Name $LogicalNetworkName
$vmNetwork = New-SCVMNetwork -Name $LogicalNetworkName -LogicalNetwork $logicalNetwork -IsolationType “NoIsolation” -Description $LogicalNetworkDescription
Write-Output $vmNetwork

You can sure make a function out of this piece of code and make a nice loop from a file with the information.

Hope it helps!