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.

Script:

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.

 

Your own virtual machine in Windows Azure!

Ah, no more setting up internal demo enviroments worrying about if it’ll be up once you’re going to demo it. No more worrying about “colleagues” reconfiguring stuff while your busy preparing slides. Now Microsoft launches virtual machines in Azure, and you can connect those to your internal environment too. Or just upload your own VHD to Azure if you don’t want to use the preconfigured ones.

Check out this blog post for more information!