PowerShell script to bulk create VM Networks in SCVMM 2012 R2

As a result of a impending migration I needed to create VM Networks in readiness for the incoming VMs. Easy enough when there are only a few you got to create, but when there are dozens of them, scripting really is the only way to go. Here’s the goss:

$LogicalNetwork = Get-SCLogicalNetwork -Name "ThrowLogicalNetworkNameHere"
$LogicalNetworkDefinition = Get-SCLogicalNetworkDefinition -Name "ThrowLogicalNetworkNameHere" -LogicalNetwork $LogicalNetwork
$VLANs = Import-Csv C:\Temp\VMNetworkCreation.csv

ForEach ($VLAN in $VLANs){

$Subnet = $VLAN.IPnet + $VLAN.Octet
$SubnetVLAN = New-SCSubnetVLan -Subnet "$Subnet" -VLanID $VLAN.VLAN
$VMNetwork = New-SCVMNetwork -Name $VLAN.Name -LogicalNetwork $LogicalNetwork -IsolationType "VLANNetwork"
$VMSubnet = New-SCVMSubnet -Name $VLAN.Name -LogicalNetworkDefinition $LogicalNetworkDefinition -SubnetVLan $SubnetVLAN -VMNetwork $VMNetwork

The csv file looked like this:

Gotta give credit where it’s due. This link gave me a head start on getting this script going. I think the author had it going for 2012 SP1, I’ve had to change it a little for R2.

1 Comment

 Add your comment
  1. Get-SCLogicalNetwork : VMM is unable to perform this operation without a connection to a Virtual Machine Manager
    management server. (Error ID: 1615)

Leave a Comment

Your email address will not be published.