VMware Cloud Community
Guv
Enthusiast
Enthusiast

List of VM's in a cluster and a resource pool

I have a cluster which I would like to list all the VM's in that cluster and the memory allocated to each VM within that cluster.

Also within that cluster, is it possible to get the total memory available and used in either GB or %, can this been done in powershell.

Also same question for a resource pool, are you able to get a list of VM's and their memory allocated to each VM with that resource pool.

Also within that that resource pool , is it possible to get the total memory available and used in either gb or %, can this been done in powershell.

0 Kudos
6 Replies
LucD
Leadership
Leadership

Since you didn't specify an output format the following script will display the values on screen.

$clusterName = <clsuter-name>
$clus = Get-Cluster -Name $clusterName

Write-Host "Cluster:" $clusterName
$memSum = 0
Get-VM -Location ($clus) | %{
	Write-Host "`t" $_.Name "Memory(GB) :" ($_.MemoryMB/1KB)
	$memSum += $_.MemoryMB
}

Write-Host "Total memory(GB) :" ($clus.ExtensionData.Summary.TotalMemory/1GB)
Write-Host "Available memory(GB) :" ($clus.ExtensionData.Summary.EffectiveMemory/1KB)
Write-Host "Used memory(GB) :" ($memSum/1KB)

foreach($resp in (Get-ResourcePool -Location ($clus))){
	Write-Host "ResourcePool:" $resp.Name
	$memSum = 0
	Get-VM -Location ($resp) | %{
		Write-Host "`t" $_.Name "Memory(GB) :" ($_.MemoryMB/1KB)
		$memSum += $_.MemoryMB
	}
	Write-Host "Used memory(GB) :" ($memSum/1KB)
}

I don't think a ResourcePool knows a concept of Total Memory.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Guv
Enthusiast
Enthusiast

Thanks

I would want this in a csv format., so where would i specify the export-csv command.

0 Kudos
Guv
Enthusiast
Enthusiast

Also for the cluster, the total memory and available memory are coming up as 0, while the used memory is giving a value

0 Kudos
LucD
Leadership
Leadership

The following produces 2 CSV files.

$clusterName = <clustername>
$clus = Get-Cluster -Name $clusterName

$report1 = @()
$memSum = 0
Get-VM -Location ($clus) | %{
	$memSum += $_.MemoryMB
	$row = "" | Select ClusterName, "ClusterTotalMem(GB)","ClusterAvailableMem(GB)", "ClusterUsedMem(GB)",VMName, "VMMem(GB)"
	$row.ClusterName = $clus.Name
	$row."ClusterTotalMem(GB)" = ($clus.ExtensionData.Summary.TotalMemory/1GB)
	$row."ClusterAvailableMem(GB)" = ($clus.ExtensionData.Summary.EffectiveMemory/1KB)
	$row.VMName = $_.Name
	$row."VMMem(GB)" = ($_.MemoryMB/1KB)
	$report1 += $row
}

$memSum /= 1KB
$report1 | %{
	$_."ClusterUsedMem(GB)" = $memSum
}

$report1 | Export-Csv "C:\Cluster-report.csv" -NoTypeInformation -UseCulture

$report2 = @()
foreach($resp in (Get-ResourcePool -Location ($clus))){
	$memSum = 0
	Get-VM -Location ($resp) -NoRecursion | %{
		$memSum += $_.MemoryMB
		$row = "" | Select ResourcePoolName, "ResourcePoolUsedMem(GB)",VMName, "VMMem(GB)"
		$row.ResourcePoolName = $resp.Name
		$row.VMName = $_.Name
		$row."VMMem(GB)" = ($_.MemoryMB/1KB)
		$report2 += $row
	}
	$memSum /= 1KB
	$report2 | where{$_.ResourcePoolName -eq $resp.Name} | %{
		$_."ResourcePoolUsedMem(GB)" = $memSum
	}
}

$report2 | Export-Csv "C:\Respool-report.csv" -NoTypeInformation -UseCulture

For the zero values, I suspect you are not using PowerCLI 4.1.

Can you check with

Get-PowerCLIVersion

If you need to stick with a PowerCLI version before 4.1, let me know and I can adapt the script.

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Guv
Enthusiast
Enthusiast

yes currently we are using V4. Can the script be adapted, as I dont think we can upgrade currently to 4.1

0 Kudos
LucD
Leadership
Leadership

Replace these 2 lines

$row."ClusterTotalMem(GB)" = ($clus.ExtensionData.Summary.TotalMemory/1GB)
$row."ClusterAvailableMem(GB)" = ($clus.ExtensionData.Summary.EffectiveMemory/1KB)

by this

$row."ClusterTotalMem(GB)" = (($clus | Get-View).Summary.TotalMemory/1GB)
$row."ClusterAvailableMem(GB)" = (($clus | Get-View).Summary.EffectiveMemory/1KB)

____________

Blog: LucD notes

Twitter: lucd22


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos