VMware Cloud Community
schnj65
Contributor
Contributor
Jump to solution

PowerCLI EntityId Convert to Actual vCenter Inventory Objects

Is there a way in PowerCLI v4 U1 to convert the EntityID column to meaningful (Human) vCenter inventory objects?

I executed the command from the PowerCLI prompt:

get-inventory | get-vipermission | Export-CSV c:\permissions.csv

Here's a subset of my current output:

EntityId

Datacenter-datacenter-2

Datacenter-datacenter-2

Folder-group-d1

Folder-group-d1

ClusterComputeResource-domain-c12827

ClusterComputeResource-domain-c1901

ClusterComputeResource-domain-c2651

VirtualMachine-vm-32714

ResourcePool-resgroup-9505

ResourcePool-resgroup-9505

ResourcePool-resgroup-12866

ResourcePool-resgroup-12866

VirtualMachine-vm-13853

VirtualMachine-vm-38244

VirtualMachine-vm-29623

VirtualMachine-vm-29623

VirtualMachine-vm-39910

VirtualMachine-vm-11687

VirtualMachine-vm-11687

thank you!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Ok, I see. Try this

Get-VIPermission | select @{N="Entity";E={(Get-View -Id $_.EntityId).Name}},Role,Principal,Propagate,IsGroup

It will list the name of the entity. And you can just pipe the output to the Export-Csv cmdlet.

The Get-Path was a function I used in that script.

It's no PowerCLI or PS cmdlet.

____________

Blog: LucD notes

Twitter: lucd22


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

View solution in original post

0 Kudos
6 Replies
schnj65
Contributor
Contributor
Jump to solution

I should add that my ultimate goal is to get the permissions for the entire vCenter hierarchy, however while the get-vipermission cmdlet works great, it provides me with ID's for objects that do not mean much - i.e VirtualMachine-vm-13853

I know that I can export the get-vm results to a csv and cross reference the ID with Name column, however there must be a way to do this all in one script without my manual effort to cross-reference the ID column with the inventory name

I am a newbie to PowerCLI and PowerShell, so pardon my ignorance

thank you

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Did you already have a look at vSphere permissions: export & import – Part 1 ?

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
schnj65
Contributor
Contributor
Jump to solution

thanks LucD!

I reviewed the link you sent and while very informative it does not resolve my issue (or perhaps I do not know enough to find the answer despite it being right in front of my eyes)

One problem I notice is that the scripts provided have a cmdlet called Get-path

It appears that get-path is no longer available in PowerCLI 4 U1 and PowerShell 2

Is there a replacement command?

Again - I am able to run get-vipermission | export-csv without issue, however the values in the Entity column are not human-friendly. I want to list the object Name property as well as the receive the EntityID when I run get-vipermission or a similar script.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Ok, I see. Try this

Get-VIPermission | select @{N="Entity";E={(Get-View -Id $_.EntityId).Name}},Role,Principal,Propagate,IsGroup

It will list the name of the entity. And you can just pipe the output to the Export-Csv cmdlet.

The Get-Path was a function I used in that script.

It's no PowerCLI or PS cmdlet.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos
schnj65
Contributor
Contributor
Jump to solution

thanks LucD - that resolved it

one very minor thing that I could live without, however I will ask

I have resource pools under HA/DRS clusters and they all have the same name (parent cluster names are different). In the Entity column is there a way to enumerate the entire path from the root vCenter object in the script results - i.e. datacenterobjectname.clusternameA.resourcepoolnameA, .... datacenterobjectname.clusternameB.resourcepoolnameA

thanks again!

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Have a look at the following script.

It shows the full path to each object returned by Get-VIPermission

filter Get-YellowFolderPath {
	process{
		Get-View -Id $_ | % {
			if($_.ResourcePool){
				$current = Get-View $_.ResourcePool
			}
			elseif($_.Parent){
				$current = Get-View $_.Parent
			}
			else{
				return $_.Name
			}
			$path = $_.Name
			do {
				$parent = $current
				if("Resources","host" -notcontains $parent.Name){
					$path = $parent.Name + "\" + $path
				}
				$current = Get-View $current.Parent
			} while ($current.Parent -ne $null)
			$path
		}
	}
}

Get-VIPermission | `
	Select @{N="Path";E={$_.EntityId | Get-YellowFolderPath}},Role,Principal,Propagate,IsGroup

Note that the script excludes the "hidden" folders Resources and host.

The hidden folder Datacenters is returned.

____________

Blog: LucD notes

Twitter: lucd22


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

0 Kudos