Figure 3.23 The complete logical network and VM network configuration
So far, we have done a lot of configuration but have not modeled our network to
SCVMM. Consider my lab environment. I configured two of the VLANs to separate the
lab environments, but suppose I have 40 or 80 or 200. This is where PowerShell is
invaluable, and I created the script that follows to automate this configuration
process.
This script creates a separate site for each VLAN, with the appropriate IP subnet and
an IP pool (which in my case is just two addresses used for the first two machines that
are domain controllers, because the rest are assigned by DHCP). In my lab, the third
octet matches the VLAN ID. This script automatically creates all 40 VLAN sites, which
run from 150 to 190, and the appropriate IP pools. You can customize the script to
meet your own needs—including changing the name of the SCVMM server and
replacing it with the logical network that all the sites should be added to (you have to
create the logical network in advance, although this could also be added to this script
if required). To find the GUID of your logical network, run the command Get-
SCLogicalNetwork | ft Name, ID -Auto:
Import-Module virtualmachinemanager
Get-VMMServer -ComputerName scvmm
#Replace this with actual ID of the Logical Network.
#Get-SCLogicalNetwork | ft name, id
$logicalNetwork = Get-SCLogicalNetwork -ID "xxxxxxxx-xxxx-xxxx-xxxx-
xxxxxxxxxxxx"
$startNumber = 150
$endNumber = 190
$vlanID = $startNumber
do
{
$allHostGroups = @()
$allHostGroups += Get-SCVMHostGroup `
-ID "0e3ba228-a059–46be-aa41–2f5cf0f4b96e"
$allSubnetVlan = @()
$allSubnetVlan += New-SCSubnetVLan -Subnet "10.1.$vlanID.0/24" `
-VLanID $vlanID