VMware Cloud Community
roblizz
Contributor
Contributor

Add ESX Host and Description

This script below works great for the little I need but I cannot figure out how to add what ESX host the vm is running on or the description. Thanks in advance for the help.

*

Connect-VIServer -Server vchost

*

$Report = @()

*

get-vm | % {

*

$vm = Get-View $_.ID

$ReportRow = "" | Select-Object VMName, Hostname, OS, VMState, ToolsStatus, ToolsVersion

$ReportRow.VMName = $vm.Name

$ReportRow.HostName = $vm.guest.hostname

$ReportRow.OS = $vm.guest.guestFullName

  1. $ReportRow.IPAddress = $vm.guest.ipAddress

$ReportRow.VMState = $vm.summary.runtime.powerState

#$ReportRow.TotalCPU = $vm.summary.config.numcpu

#$ReportRow.TotalMemory = $vm.summary.config.memorysizemb

#$ReportRow.MemoryUsage = $vm.summary.quickStats.guestMemoryUsage

#$ReportRow.TotalNics = $vm.summary.config.numEthernetCards

$ReportRow.ToolsStatus = $vm.guest.toolsstatus

$ReportRow.ToolsVersion = $vm.config.tools.toolsversion

#$ReportRow.MemoryLimit = $vm.resourceconfig.memoryallocation.limit

#$ReportRow.MemoryReservation = $vm.resourceconfig.memoryallocation.reservation

$Report += $ReportRow

}

$Report | Export-CSV c:\export.csv

  1. I found this code at http://www.yellow-bricks.com/2008/06/27/vm-report/

0 Kudos
2 Replies
harkamal
Expert
Expert

$_.Host.Name get you the host on which the vm is running on.

Connect-VIServer -Server vchost


$Report = @()


Get-VM | % { 


 $vm = Get-View $_.ID
 $ReportRow = "" | Select-Object VMName, Hostname, OS, VMState, ToolsStatus, ToolsVersion
 $ReportRow.VMName = $vm.Name
 $ReportRow.HostName = $_.Host.Name
 $ReportRow.OS = $vm.guest.guestFullName


 # $ReportRow.IPAddress = $vm.guest.ipAddress
 $ReportRow.VMState = $vm.summary.runtime.powerState
 #$ReportRow.TotalCPU = $vm.summary.config.numcpu
 #$ReportRow.TotalMemory = $vm.summary.config.memorysizemb
 #$ReportRow.MemoryUsage = $vm.summary.quickStats.guestMemoryUsage
 #$ReportRow.TotalNics = $vm.summary.config.numEthernetCards
 $ReportRow.ToolsStatus = $vm.guest.toolsstatus
 $ReportRow.ToolsVersion = $vm.config.tools.toolsversion
 #$ReportRow.MemoryLimit = $vm.resourceconfig.memoryallocation.limit
 #$ReportRow.MemoryReservation = $vm.resourceconfig.memoryallocation.reservation
 $Report += $ReportRow
}
$Report | Export-CSV c:\export.csv

0 Kudos
harkamal
Expert
Expert

basically, you get the vm in a variable and see its props

 
$vm = get-VM <MyVm>
$vm.Host.Name

$vm | FL *

0 Kudos