VMware Cloud Community
gerf0727
Enthusiast
Enthusiast

How to list VMs within a host, datastore inside the vCenter?

Hello,

Something similar to this script

Get-Cluster -Name UPIUCSCluster01 | Get-VM | Select Name,@{N="OS";E={$_.Guest.OSFullName}},@{N="DNS";E={[string]::Join(',',($_.Guest.ExtensionData.Net[0].DnsConfig.IpAddress))}},@{N="Host";E={$_.Host.Name}},    @{N="Datastore";E={[string]::Join(',',(Get-View $_.DatastoreIdList | %{$_.Name}))}} |Export-Csv .\report.csv -NoTypeInformation -UseCulture

But, instead og giving a cluster name, i just want to add the ESXi

Or can we list everyting inside the vCenter following the same format as above ?

Thanks,

Reply
0 Kudos
3 Replies
jonathanp
Expert
Expert

Not sure if this is what you are looking for, but this is giving a report that will list VMs , their DS Name / number... etc...(and can be modified easily to add almost all that you want/need)

___________________________________________________

You can add host to the below script by modifying :

$row = "" | Select-Object "Virtual Machine", "LUN Name", "LUN Number", CapacityGB, FreeSpaceGB

to

$row = "" | Select-Object "Host Name", "Virtual Machine", "LUN Name", "LUN Number", CapacityGB, FreeSpaceGB

and adding :

$row."Host Name" = $vmhost.Name

____________________________________________________

$report = @()
foreach ($vm in (Get-VM))
{
$vmhost = Get-VMHost -VM $vm
$dsinfo = Get-VM $vm | Get-Datastore | Select Name,CapacityGB,FreeSpaceGB,@{N="Canonical Name";E={[string]::Join(',',($_.Extensiondata.Info.Vmfs.Extent | %{$_.DiskName}))}}
foreach ( $item in $dsinfo)
{
$lunnumber = Get-VMHost $vmhost | Get-ScsiLun $item."Canonical Name"
$row = "" | Select-Object "Virtual Machine", "LUN Name", "LUN Number", CapacityGB, FreeSpaceGB
$row."Virtual Machine" = $vm.Name
$row."LUN Name" = $item.Name
$row."LUN Number" = $lunnumber.ConsoleDeviceName
$row.CapacityGB = $item.CapacityGB
$row.FreeSpaceGB = $item.FreeSpaceGB
$report += $row
}
}

$report | Export-Csv "C:\report.csv" -noTypeInformation

Reply
0 Kudos
gerf0727
Enthusiast
Enthusiast

Hmm not quite, i need the OS

Reply
0 Kudos
gerf0727
Enthusiast
Enthusiast

Never mind, I got it

Get-VMHost "HOSTNAME" | Get-VM | Select Name,@{N="OS";E={$_.Guest.OSFullName}},@{N="DNS";E={[string]::Join(',',($_.Guest.ExtensionData.Net[0].DnsConfig.IpAddress))}},@{N="Host";E={$_.Host.Name}},    @{N="Datastore";E={[string]::Join(',',(Get-View $_.DatastoreIdList | %{$_.Name}))}} |Export-Csv C:\scripts\VMware\ESXI05_VM_OS_report.csv -NoTypeInformation -UseCulture

Reply
0 Kudos