Hyper-V, PowerShell, SCVMM: Audit Dynamic MAC address ranges
Before you continue please consider clicking on one of the horrible ads. I know they are a pain but they help me pay for the hosting of this site. It owes me a lot of money. Sob story over.
I am in a more PowerShell and less hands on technical role at the moment. The way it seems to work is someone will say to me.
"We need to audit this on these hosts"
and then I rustle up a bit of code that does said thing.
This script will tell you the dynamic MAC address ranges being dished out by hosts that are being managed by SCVMM, and save it as a CSV via a hash table.
$ClusterNodes = Invoke-Command -ComputerName <nameofSCVMM> -ScriptBlock {Get-SCVMHost}
$ClusterallMACRanges =@()
Foreach ($ClusterNode in $ClusterNodes)
{
$ClusterMACRanges =@{}
$ClusterMACRanges.add("Name",$ClusterNode.Name)
$NodeMacRange = Get-VMHost -ComputerName $ClusterNode
$ClusterMACRanges.add("MACAddressMinimum",$NodeMacRange.MacAddressMinimum)
$ClusterMACRanges.add("MacAddressMaximum",$NodeMacRange.MacAddressMaximum)
$ClusterallMACRanges = $ClusterallMACRanges + $ClusterMACRanges
}
# Convert the hash table to CSV format manually as the in-built functions suck
$ClusterHostMACInfoST = $null
$ClusterHostMACInfoST += "Hostname"
$ClusterHostMACInfoST += ", "
$ClusterHostMACInfoST += "MACAddressMinimum"
$ClusterHostMACInfoST += ", "
$ClusterHostMACInfoST += "MacAddressMaximum"
$ClusterHostMACInfoST += "`n"
foreach ($ClusterallMACRange in $ClusterallMACRanges)
{
$ClusterHostMACInfoST += $ClusterallMACRange.Name
$ClusterHostMACInfoST += ", "
$ClusterHostMACInfoST += $ClusterallMACRange.MACAddressMinimum
$ClusterHostMACInfoST += ", "
$ClusterHostMACInfoST += $ClusterallMACRange.MacAddressMaximum
$ClusterHostMACInfoST += "`n"
}
$ClusterHostMACInfoST |Out-File -FilePath c:\temp\macs.csv