Jun 172013
 

This code will help you step though the creation of VMotion networks on your hosts.

######### the vars ####
$thehost = “host1.pcli.me”
$theVswitch = “vSwitch1″
$vmotion1IP = “1.1.1.1″
$vmotion2IP = “1.1.1.2″
$theSubnetMask = “255.255.255.254″

### the code ###
### Create the Vmotion Port groups
get-vmhost -name $thehost | Get-VirtualSwitch -name $theVswitch | new-VirtualPortGroup -name vmotion1 -vlanid 0
get-vmhost -name $thehost | Get-VirtualSwitch -name $theVswitch | new-VirtualPortGroup -name vmotion2 -vlanid 0

### Create the Vmotion VMKernels
New-VMHostNetworkAdapter -VMHost $thehost -PortGroup vmotion1 -VirtualSwitch $theVswitch -IP $vmotion1IP -SubnetMask $theSubnetMask -VMotionEnabled:$true
New-VMHostNetworkAdapter -VMHost $thehost -PortGroup vmotion2 -VirtualSwitch $theVswitch -IP $vmotion2IP -SubnetMask $theSubnetMask -VMotionEnabled:$true

### Change the Network Teaming Policy to Active/Standby on both vmotion network port groups.
### Use this code if you are using two vmotion networks and want them to run on seperate NICs
$thingy = get-virtualswitch -vmhost $thehost -name $theVswitch | Get-virtualportgroup -name “vmotion1″ | get-nicteamingPolicy
$thingy | Set-NicTeamingPolicy -MakeNicActive “vmnic1″ -MakeNicStandby “vmnic2″
$thingy = get-virtualswitch -vmhost $thehost -name $theVswitch | Get-virtualportgroup -name “vmotion2″ | get-nicteamingPolicy
$thingy | Set-NicTeamingPolicy -MakeNicActive “vmnic2″ -MakeNicStandby “vmnic1″

VMWare Links:
http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/New-VirtualPortGroup.html
http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/New-VMHostNetworkAdapter.html
http://www.vmware.com/support/developer/windowstoolkit/wintk40u1/html/Set-NicTeamingPolicy.html