• Home
  • Our Services
  • Presentations
  • About me
  • Links
  • Contact Us
  • Privacy Policy

Cloud and Datacenter Management

Cloud at your fingertips
  • Home
  • Our Services
  • Presentations
  • About me
  • Links
  • Contact Us
  • Privacy Policy
Home  /  SystemCenter  /  Create Virtual networks in VMM with Powershell
31 January 2015

Create Virtual networks in VMM with Powershell

Written by alexandre@verkinderen.com
SystemCenter network, Networking, powershell, SCVMM, VMM Leave a Comment

I’m now working on a HyperV migration project to move all servers from one datacenter to a new datacenter. This implies that I need to move all virtual machines with HyperV replica, configure virtual networks in the new datacenter etc.

My customer is using VLAN Isolation in VMM. For more information about Network isolation have a look here.  Service Providers often use dedicated VLANs and PVLANs to isolate different tenants from one another.  As described in the blog post I’m using one logical network for all of the tenants, and configure sites, vlans and networks per tenant. Multiple VM networks may be linked to the same Logical Network if Network Virtualization is enabled, with each one of these VM Networks separated from and totally unaware of the existence of any of the others. But if you have a lot tenants this is a lot of manual work 🙂

As I couldn’t reuse the old VMM server and config in the new datacenter for several reasons I have to re-configure the networking (Vlans, subnets, network sites, etc)  configuration from scratch. So  I found a way to automate all of this labour intensive tasks with Powershell.

This blogpost is not about how to configure step by step networking in VMM, if you need more information on how to configure networking in vmm have a look here  or download the Networking white paper from Kristian Nese .

The key thing to be able to keep an overview (if you are using networking in VMM) and for easy troubleshooting is NAMING CONVENTION. Without a proper naming convention it will be very hard to now which VMnetwork is connected to which site and using this vlan or this subnet…

So I’m using the following naming convention:

  • Logical Network Name = “Customer – Logical Network – Name”
  • Network Site = “Customer + VLANname + Site + VLanID”
  • Virtual Network Name =  “Customer + VLANname + VMNetwork + VLanID”
  •  SubnetName = “Customer + VLANname + VMSubnet+ VLanID”
  • etc

You get the point.

 

Now let’s get started!

First of all the the script assumes you already have a Logical network defined using VLAN based indepentend networks.

logical network

 

Open Powershell ISE and copy past the script. Next you just change the following variables in the scrip to match your own:

[xml]
<pre>$Subnet = "10.100.40.10/24"
$VlanID = 521
$VlanName = "ITSystems"
$Customer = "Contoso"</pre>
[/xml]

The end result is:

  • All my network sites are created with proper naming convention
  • Associated Vlans and subnet defined

network sites

and Virtual Networks created:

vmnetworks

and Port Profile changed as well.

 

PowerShell
1
Below you can find the whole script:

[xml]

PowerShell Script to configure Networking in VMM

#

The script assumes you already have defined your networkig in VMM as explained here for examaple http://charbelnemnom.com/2014/05/create-a-converged-network-fabric-in-vmm-2012-r2/

Once this is done and you have your logical network, your logical swtich and your port profile, you need to create sites and VLAN per tenant if your using VLAN isolation

So the next labour intensive task is to create sites,vlans, subnet, reconfigure the portprofile with new site ,create a virtual network etc manually.

Auhtor: Alexandre Verkinderen

#Get Variable
#Specify your existing Logical network name
$NetworkName = "Contoso – Logical Network – Tenants"
#Specify your existing PortProfile.
$portProfile = Get-SCNativeUplinkPortProfile -Name "Contoso – Reference – Profile" -ID "a3c36703-4e0b-4b25-baa7-69b347be8c72"
#Specify the new subnet, the new vlan ID and a Name for the new network site
############################
$Subnet = "10.100.40.10/24"
$VlanID = 521
$VlanName = "ITSystems"
$Customer = "Contoso"
############################

$NetworkSiteName = $Customer + " – " + $VlanName+ " – Site – " + $VlanID
$VMNetworkName = $Customer + " – " +$VlanName+ " – VMNetwork – " + $VlanID
$VMSubnetName = $Customer + " – " + $VlanName+ " – VMSubnet – " + $VlanID

#First we get the Logical network that has already been created
$logicalNetwork = Get-SCLogicalNetwork | Where {$.Name -Match $NetworkName }
#The Set-SCLogicalNetwork cmdlet changes the properties of a System Center Virtual Machine Manager (VMM) logical network object.
Set-SCLogicalNetwork -Name $NetworkName -Description "" -LogicalNetwork $logicalNetwork -RunAsynchronously -EnableNetworkVirtualization $false -UseGRE $false -LogicalNetworkDefinitionIsolation $true
#We are defining the new network settings for the All hosts group. If you need more granularity you can specify other host group names here
$allHostGroups = @()
$allHostGroups += Get-SCVMHostGroup | Where {$
.Name -Match "All Hosts" }
$allSubnetVlan = @()
$allSubnetVlan += New-SCSubnetVLan -Subnet $Subnet -VLanID $VlanID

#CreateSite
#he New-SCLogicalNetworkDefinition cmdlet creates a definition for a System Center Virtual Machine Manager (VMM) logical network. The logical network can be associated with one or more host groups. A logical network definition is also called a network site.
#After you create a new logical network, use the logical network definitinon to assign IP subnets and VLANs to the logical network.
New-SCLogicalNetworkDefinition -Name $NetworkSiteName -LogicalNetwork $logicalNetwork -VMHostGroup $allHostGroups -SubnetVLan $allSubnetVlan -RunAsynchronously
Write-Output "Site ok"

#CreateVMNetwork
#The New-SCVMNetwork cmdlet creates a virtual machine network. Virtual machine networks support multiple methods of isolation: No isolation, network virtualization, external, and VLAN
$vmNetwork = New-SCVMNetwork -Name $VMNetworkName -LogicalNetwork $logicalNetwork -IsolationType "VLANNetwork"

$logicalNetworkDefinition = Get-SCLogicalNetworkDefinition -Name $NetworkSiteName -LogicalNetwork $logicalNetwork
$subnetVLAN = New-SCSubnetVLan -Subnet $Subnet -VLanID $VlanID
$vmSubnet = New-SCVMSubnet -Name $VMSubnetName -LogicalNetworkDefinition $logicalNetworkDefinition -SubnetVLan $subnetVLAN -VMNetwork $vmNetwork
Write-Output "VMNetwork ok"

#ChangePortProfile
$logicalNetworkDefinitionsToAdd = @()
$logicalNetworkDefinitionsToAdd += Get-SCLogicalNetworkDefinition -Name $NetworkSiteName
Set-SCNativeUplinkPortProfile -NativeUplinkPortProfile $portProfile -Name "Contoso – Reference – Profile" -Description "" -EnableNetworkVirtualization $true -LBFOLoadBalancingAlgorithm "Dynamic" -LBFOTeamMode "SwitchIndependent" -RunAsynchronously -AddLogicalNetworkDefinition $logicalNetworkDefinitionsToAdd
Write-Output "Profile Changed"
[/xml]

You can also download the whole script from here: https://gallery.technet.microsoft.com/Configure-Virtual-Machine-a362f121

Hope this helps,

Alexandre Verkinderen

Related

Share On
Share on Facebook
Share on Twitter
Share on Google+
Share on LinkedIn
alexandre@verkinderen.com

 Previous Article Optimize Azure website performance
Next Article   Enable Hyper-V Replica for all virtual machines in a specific Cloud

Related Posts

  • Download MSIgnite 2018 slides

    02/10/2018
  • How to define an Azure Limited Admin custom role

    11/09/2017
  • Enabling Azure Network Security Group (NSG) flow logging in bulk

    06/06/2017

Leave a Reply Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Recent Posts

  • Azure API Management Consumption Tier
  • Real Time Twitter sentiment analysis with Azure Cognitive Services
  • Move Managed Disks to another subscription
  • Download MSIgnite 2018 slides
  • Azure Files Updates from Ignite

Twitter

Goodreads

Tags

acs Advisor Agent Agents audit collection service azure Azure Cloud community cubesys end to end monitoring Essentials Events General hotfix HP Issue KB Management Pack manuals MVP Opalis Operations Manager 2007 Opmsgr 2007 R2 opsmgr opsmgr 2012 Opsmgr DB opsmgr R2 Performance powershell R2 reporting SCCM scom SCSM SCVMM service level dashboard Service Manager sql system center teched Uncategorized WAP web application monitoring Windows 2008

Categories

  • Azure
  • IOT
  • it camps
  • MAS
  • OMS
  • Powershell
  • Sharepoint
  • SystemCenter
  • Technet
  • Uncategorized
  • WAP
  • Windows 8

Archives

  • January 2019
  • November 2018
  • October 2018
  • September 2018
  • January 2018
  • December 2017
  • November 2017
  • September 2017
  • June 2017
  • May 2017
  • April 2017
  • March 2017
  • February 2017
  • January 2017
  • November 2016
  • October 2016
  • September 2016
  • July 2016
  • June 2016
  • January 2016
  • December 2015
  • November 2015
  • May 2015
  • April 2015
  • March 2015
  • February 2015
  • January 2015
  • December 2014
  • March 2014
  • January 2014
  • December 2013
  • November 2013
  • May 2013
  • April 2013
  • March 2013
  • February 2013
  • November 2012
  • June 2011
  • May 2011
  • April 2011
  • January 2011
  • December 2010
  • November 2010
  • October 2010
  • September 2010
  • July 2010
  • May 2010
  • April 2010
  • March 2010
  • February 2010
  • January 2010
  • December 2009
  • November 2009
  • October 2009
  • September 2009
  • July 2009
  • June 2009
  • May 2009
  • April 2009
  • March 2009
  • February 2009
  • January 2009
  • November 2008
  • October 2008
  • September 2008
  • August 2008
  • July 2008
  • June 2008
  • May 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
© Copyright 2017. Alexandre Verkinderen