I am trying to use PowerShell to create a very simple (or so I thought) report from VMM 2012 R2 that would help me hunt down VMs configured with Dynamic MAC address on their virtual NICs. My enterprise uses static MACs across the board.
So, excluding all the wrapper code that would handle E-mailing the report to me, the main bulk of what gathers the info is as follows:
$VMs = Get-VM
foreach ($VM in $VMs)
$VMNIC = $VM | Get-SCVirtualNetworkAdapter
if ($VMNIC.MACAddressType -eq "Dynamic")
$VMNamesHTML += ConvertTo-HTML -InputObject $VM -Property Name -Fragment
$VMNICsHTML += ConvertTo-HTML -InputObject $VMNIC -Property MACAddressType -Fragment
ConvertTo-HTML -Body "$VMNameHTML $VMNICHTML" >>output.html
My problem with this solution is the output format. The ConvertTo-HTML cmdlet lacks the ability to concatenate multiple variables into the body in multi-column
form. I'm looking for someone to help me get this information formatted in a more readable fashion. Here is what I get from the code above:
For readability sake, the output should look more like this:
So in the case of there being multiple VMs and multiple MAC addresses, the information is easily readable without having to keep track of what line goes with what MAC address, as would be the case of everything is formatted in a single column.
This has become enormously frustrating for me. Searching the net has resulted in massively divergent solutions to similar problems others have experienced.
ConvertTo-HTML has -InputObject and -Properties parameters. Unfortunately for me, as is the case with most things PowerShell I run into, they're half-baked beyond belief. -InputObject does not allow for multiple objects to be passed, as it should. And therefore -Properties, which should be able to select properties from the multiple input objects by simply using an index number, does not.
Thank you in advance for any solutions you might dream up.