VMware Cloud Community
Guv
Enthusiast
Enthusiast

List Vm's and their IP in a cluster

Can someone advise please or refresh, I have 2 clusters in my virtual centre and I want to list the Vm's, their OS and their IP addresses in these 2 clusters.

Can anyone advise please

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership

Can you try this

Get-Cluster "cluster1","cluster2" | Get-VM | select Name,@{N="OS";E={$_.Guest.OSFullName}},@{N="IP addr";E={$_.Guest.IPAddress[0]}}

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
LucD
Leadership
Leadership

And if you want to include the clustername in the report, you can do

Get-Cluster "cluster1","cluster2" | %{
	$cluster = $_
	Get-VM -Location $cluster | `
          select Name,@{N="Cluster";E={$cluster.Name}},@{N="IP addr";E={$_.Guest.IPAddress[0]}},@{N="OS";E={$_.Guest.OSFullName}}
}

____________

Blog: LucD notes

Twitter: lucd22


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

Reply
0 Kudos
RvdNieuwendijk
Leadership
Leadership

I made a different solution based on the New-VIProperty cmdlet:

New-VIProperty -Name "OSFullname" -ObjectType VirtualMachine `
	-Value {
		param($vm)
		$vm.Guest.OSFullName		
	}  -Force
	
New-VIProperty -Name "IPAddress" -ObjectType VirtualMachine `
	-Value {
		param($vm)
		$vm.Guest.IPAddress		
	}  -Force
	
New-VIProperty -Name "Cluster" -ObjectType VirtualMachine `
	-Value {
		param($vm)
		$vm.Host.Parent.Name		
	}  -Force

Get-Cluster "cluster1","cluster2" | Get-VM | Select Cluster,Name,OSFullname,IPAddress

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
Reply
0 Kudos