Help setting VM's to use Static MAC using Powershell

Hi all,

I would like to create a powershell script to set all VM's with a Static MAC address on one of our Hyper-V Clusters.

So far I've managed to do this in the gui buy creating a new MAC Pool then shutting down 1 of the VM's and changing the network card from dynamic to static 00:00:00:00:00:00 within it's properties. After the changes are applied the VM is given a MAC address from my MAC pool range.

I'd now like to create a script to do this for the remaining VM's - could somebody possibly help me out.. I have tried using the 'view script' button but I don't understand the output.

Many thanks for your help

Robbie

April 27th, 2015 11:00am

Hi,

For your specific need the following script should work, just replace the Cluster and Default Mac Address Pool Name.

$ClusterName = "CLUSTER_NAME"
$MacAddressPool = Get-SCMACAddressPool -Name "Default MAC address pool"
Get-ScvmHostCluster $ClusterName|%{
	$_.nodes |%{
		$VMhostName = $_.name
		
		Get-SCVirtualMachine |?{$_.VMhost -eq $VMhostName} |%{
			$VM = $_ 
			Get-SCVirtualNetworkAdapter -VM $VM |%{
				$VNIC = $_
				Set-SCVirtualNetworkAdapter -VirtualNetworkAdapter $VNIC -MACAddressType "Static" 
				Grant-SCMACAddress -MACAddressPool $MACAddressPool -VirtualNetworkAdapter $VNIC
				write-host $vm.name Physical Address $Vnic.PhysicalAddress -ForegroundColor Yellow
			}
			
			
		}		
	}
}


Free Windows Admin Tool Kit Click here and download it now
April 28th, 2015 8:06am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics