Automatic network assignment in your private cloud with PowerShell

Might not be the prettiest PS-script ever written but it does what it says on the box! I’m using this script to automatically assign the right network to the VM’s deployed in my SCVMM. The reason for the script is that the clouds in my VMM are connected to internal networks and not external facing nics. This is so every lab user can do whatever they want, without having to worry about for example DHCP or other disrupting services.


import-module "C:Program FilesMicrosoft System Center 2012Virtual Machine ManagerbinpsModulesvirtualmachinemanagervirtualmachinemanager.psd1"
$vm = get-vm | where {$_.Cloud -match "LabNet01"}
Foreach ( $singleVM in $VM) { $Adapter = Get-VirtualNetworkAdapter -VM $singleVM set-VirtualNetworkAdapter -VirtualNetworkAdapter $Adapter -VirtualNetwork "LabNet01" }

If you have more clouds you’ll need one script per cloud, stuff to edit is name of cloud “{$_.Cloud -match “LabNet01″} ” and the name of the virtual network “VirtualNetwork “LabNet01″”. I’m running the scripts as scheduled tasks every 120 seconds, this means that a machine created in SCVMM will within two minutes be assigned the right network.


Leave a Reply

Your email address will not be published. Required fields are marked *