VMware Cloud Community
ViCoS
Contributor
Contributor
Jump to solution

Getting resource pool structure

Hi,

I'm trying to get the virtual machines in our resource pools. We've got a resource pool structure like this:

Department1

-


Dev

-


Tier1

-


Tier2

-


Prod

-


Tier1

-


Tier2

Department2

-


Dev

-


Tier1

-


Tier2

-


Prod

-


Tier1

-


Tier2

Running get-resourcepools the output is like this:

Name Id

=====================

Resources ResourcePool-resgroup-8

Tier1 ResourcePool-resgroup-1011

Tier2 ResourcePool-resgroup-1012

Department1 ResourcePool-resgroup-305

Prod ResourcePool-resgroup-306

Tier1 ResourcePool-resgroup-307

Tier2 ResourcePool-resgroup-308

Department2 ResourcePool-resgroup-291

Tier2 ResourcePool-resgroup-770

Prod ResourcePool-resgroup-294

Tier1 ResourcePool-resgroup-296

Tier2 ResourcePool-resgroup-297

Dev ResourcePool-resgroup-767

Dev ResourcePool-resgroup-759

Tier1 ResourcePool-resgroup-769

If I get the vms on each resourcepool in the above list , I wouldnt be able to distinguish whether Tier1 is from the Department1\Dev branch or the Department2\Prod branch.

How can I get that information, ie, the "Tier1" resourcepool (ResourcePool-resgroup-296) is in which parent resource group.

thanks,

Chi

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There are 2 things to consider before we tackle the script.

1) Resource pools can be created in 2 different locations, under a Cluster and under a standalone Host

2) In the vSphere environment there are some hidden folders. One of these is the parent resource pool called "Resources".

You will find this folder under each cluster and under each standalone host.

The script uses a function, called Get-RpPath, which makes it a lot easier to recursively descend the resource pool structure

The script now prints the hidden folder "Resources" as the start but this can be replaced by the name of the cluster or standalone host just above.

The script starts by collecting all the hidden "Resources" folders in your vSphere enviroment and then recursively descends each of the in search of sub-resourcepools.

$indent = 4

function Get-RpPath{
	param($rp, $level)

	Write-Host ($rp.Name).PadLeft($level + $rp.Name.Length, "-")
	foreach($child in $rp.ChildConfiguration){
		$nrp = Get-View -Id $child.Entity
		if($nrp.GetType().Name -eq "ResourcePool"){
			Get-RpPath $nrp ($level + $indent)
		}
	}
}

$clusters = Get-Cluster
$hosts = Get-VMHost | where {-not ($_.ParentId -like "Cluster*")}

$RProot = $clusters | % {
	Get-Inventory -NoRecursion -Location $_ | where {$_.gettype().Name -eq "ResourcePoolImpl"}
}
$RProot += ($hosts | % {
	Get-Inventory -NoRecursion -Location $_ | where {$_.gettype().Name -eq "ResourcePoolImpl"}
})

$RProot | Get-View | % {
	Get-RpPath $_ 0
}


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

View solution in original post

Reply
0 Kudos
3 Replies
LucD
Leadership
Leadership
Jump to solution

There are 2 things to consider before we tackle the script.

1) Resource pools can be created in 2 different locations, under a Cluster and under a standalone Host

2) In the vSphere environment there are some hidden folders. One of these is the parent resource pool called "Resources".

You will find this folder under each cluster and under each standalone host.

The script uses a function, called Get-RpPath, which makes it a lot easier to recursively descend the resource pool structure

The script now prints the hidden folder "Resources" as the start but this can be replaced by the name of the cluster or standalone host just above.

The script starts by collecting all the hidden "Resources" folders in your vSphere enviroment and then recursively descends each of the in search of sub-resourcepools.

$indent = 4

function Get-RpPath{
	param($rp, $level)

	Write-Host ($rp.Name).PadLeft($level + $rp.Name.Length, "-")
	foreach($child in $rp.ChildConfiguration){
		$nrp = Get-View -Id $child.Entity
		if($nrp.GetType().Name -eq "ResourcePool"){
			Get-RpPath $nrp ($level + $indent)
		}
	}
}

$clusters = Get-Cluster
$hosts = Get-VMHost | where {-not ($_.ParentId -like "Cluster*")}

$RProot = $clusters | % {
	Get-Inventory -NoRecursion -Location $_ | where {$_.gettype().Name -eq "ResourcePoolImpl"}
}
$RProot += ($hosts | % {
	Get-Inventory -NoRecursion -Location $_ | where {$_.gettype().Name -eq "ResourcePoolImpl"}
})

$RProot | Get-View | % {
	Get-RpPath $_ 0
}


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

Reply
0 Kudos
DougBaer
Commander
Commander
Jump to solution

You could try walking the resource pool tree yourself:


$top = Get-resourcePool -norecursion -location (Get-Cluster CLUSTERNAME)

function walkRP ($location,$depth) 
{
	Write-Host ($location.Name).PadLeft($depth + $_.Name.Length, '-')
	Get-VM -Location $location | % { Write-Host ($_.Name).PadLeft($depth + $_.Name.Length + 2, " ") }
	Get-ResourcePool -norecursion -location $location | % { if ($_) {walkRP $_ ($depth+2)} }
}

walkRP $top 0

Message was edited by: DougBaer -- should have refreshed the thread before posting! Oh, well... Luc's script is more complete! Smiley Happy

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
ViCoS
Contributor
Contributor
Jump to solution

Many thanks for this. Much appreciated.

Reply
0 Kudos