Braxhane

Reports for Powered on VMs MAC and IP

Jan 27th, 2015
73
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     $reportedvms=New-Object System.Collections.ArrayList
  2.     $vms=get-view -viewtype virtualmachine -Filter @{'Runtime.PowerState'='poweredOn'}  |Sort-Object -Property {  $_.Config.Hardware.Device |  where {$_ -is [VMware.Vim.VirtualEthernetCard]} |  Measure-Object | select -ExpandProperty Count} -Descending
  3.      
  4.     foreach($vm in $vms){ $reportedvm = New-Object PSObject
  5.     Add-Member -Inputobject $reportedvm -MemberType NoteProperty -name Guest -value $vm.Name
  6.      
  7.     $networkcards=$vm.guest.net | ?{$_.DeviceConfigId -ne -1}
  8.     $i=0
  9.     foreach($ntwkcard in $networkcards){
  10.     Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.MacAddress" -Value $ntwkcard.Macaddress  
  11.     Add-Member -InputObject $reportedvm -MemberType NoteProperty -Name "networkcard${i}.IpAddress" -Value $($ntwkcard.IpAddress|?{$_ -like "*.*"})
  12.     $i++
  13.     }
  14.     $reportedvms.add($reportedvm)|Out-Null
  15.     }
  16.      
  17.     $reportedvms|Export-Csv c:\tools\myreport.csv
RAW Paste Data