Doh I guess I spoke too soon, I have one last oddity everything else is working.
I had to put in some Write-Host statements to see what was going on.
I have a 2 VMs lets call them VM01 and VM01v6.
VM01 has an IP that ends in .5 and VM02v6 has an IP that ends in .6
VM01 has 4gb of ram and VM01v6 has 16gb
But when the script runs for some reason on VM01 it shows IPs for both VMs for VM01 then tosses errors when it tries to do the math for RAM and such. When I tried the Write-Host. Here is what I see
$VMStats.TotalMemoryGB = [math]::Round($vm.summary.config.memorysizemb*1MB/1GB,2)
Write-Host "MemoryGB: " $VMStats.TotalMemoryGB
Output to screen:
MemoryMB: 16384 4096
When it tries to do the math
$VMStats.TotalMemoryGB = [math]::Round($vm.summary.config.memorysizemb*1MB/1GB,2)
I get an error:
Method invocation failed because [System.Object[]] doesn't contain a method named 'op_Division'.
$VMStats.TotalMemoryGB = [math]::Round($vm.summary.config.memorysizemb*1MB/1G ...
CategoryInfo: InvalidOperation: (op_Division:String) [], RuntimeException
Here is the current Script
#Get a list of DataCenters in sorted order
$DCs=get-datacenter | sort
foreach ($dc in $DCs){
$ClusterList=get-datacenter $dc | get-cluster | sort
foreach ($cluster in $ClusterList){
$VMList = get-cluster $cluster | get-vm | sort
foreach($vm in $VMList){
Write-Host $vm.Name #Just for testing and seeing what VMs are throwing errors if any while I test
$vm=Get-View -ViewType Virtualmachine -SearchRoot $cluster.ExtensionData.MoRef -filter @{"Name"="$($vm.Name)"}
# The Report
$VMStats = "" | Select-Object VMName, DC, Cluster, ESXiHost, Folder, HardwareVersion, OS, VMstate, TotalCPU, CPUAffinity, CPUreservation, TotalMemoryGB, MemoryReservationMB, TotalNics, IPAddress, MacAddress, Portgroup, Datastore, ProvisionedSpaceGB, UsedSpaceGB, ToolsStatus, ToolsVersion
#Get Parent Details From vCenter (Data Center, Cluster, ESXi Host, Folder)
$VMStats.DC = $DC
$VMStats.Cluster = $cluster
$VMStats.ESXiHost = Get-View -Id $vm.Runtime.Host -property Name | select -ExpandProperty Name
$VMStats.Folder = Get-View -Id $vm.Parent -Property 'Name' | select -ExpandProperty Name
# Basic Info about the VM (Hostname, HardwareVersion, ESXiHost, IPAddress(s), OS, Powered/ON/Off
$VMStats.VMName = $vm.Name
$VMStats.HardwareVersion = $vm.config.Version
$VMStats.IPAddress = $vm.guest.IPAddress -join ', '
$VMStats.OS = $vm.Config.GuestFullName
$VMStats.VMState = $vm.summary.runtime.powerState
# CPU Info
$VMStats.TotalCPU = $vm.summary.config.numcpu
$VMStats.CPUAffinity = $vm.Config.CpuAffinity
$VMStats.CPUreservation = $vm.resourceconfig.cpuallocation.reservation
# Memory Info
$VMStats.TotalMemoryGB = [math]::Round($vm.summary.config.memorysizemb*1MB/1GB,2)
$VMStats.MemoryReservationMB = $vm.resourceconfig.memoryallocation.reservation
#Network Info
$VMStats.TotalNics = $vm.summary.config.numEthernetCards
$VMStats.MacAddress = $vm.config.hardware.device.macaddress
#VLAN - Portgroup info
if ($vm.Network) {$VMStats.Portgroup = Get-View -Id $vm.Network -Property Name | select -ExpandProperty Name}
#Storage Info
$VMStats.Datastore = $vm.Config.DatastoreURL[0].Name
$VMStats.ProvisionedSpaceGB = [math]::Round($vm.Summary.Storage.UnCommitted/1GB,2)
$VMStats.UsedSpaceGB = [math]::Round($vm.Summary.Storage.Committed/1GB,2)
#VMware Tools Info
$VMStats.ToolsStatus = $vm.guest.toolsstatus
$VMStats.ToolsVersion = $vm.config.tools.toolsversion
#Add details to the report
$Report += $VMStats
}
}
}