Pages: [1]
Print
Author Topic: Custom Column names  (Read 1137 times)
aflora
Newbie
*
Posts: 16


View Profile
« on: September 27, 2009, 06:28:23 PM »

Hi

I'm trying to customise the columns to closely resemble the permissions tab in the VIC but I'm having some trouble populating the Virtual Machine column.

Here's the code:

Variables
$report = @()
$inherited = $true
$htmlfile = "d:\Vm_perms.htm"
$authMgr = Get-View AuthorizationManager
$roles = @{}



foreach($role in $authMgr.RoleList){
$roleshttp://$role.RoleId = $role.Name
}


Get-View -Viewtype VirtualMachine | % {


$exist = Get-VIObjectByVIView -MORef $_.MoRef -ErrorAction SilentlyContinue
if($exist -ne $null){
$current = Get-View $_.Parent
$path = $_.Name
do {
$parent = $current
if($parent.Name -ne "vm"){$path = $parent.Name + "\" + $path}
$current = Get-View $current.Parent
} while ($current.Parent -ne $null)


$permissions = $authMgr.RetrieveEntityPermissions($_.MoRef, $inherited)
if($permissions.Length -ne 0){
foreach($perm in $permissions){

$report += $perm | Select @{Name = "Virtual Machine" ; Expression = {}},
@{Name = "User/Group" ; Expression = {$perm.Principal}} , @{Name = "Role" ; Expression = {$roleshttp://$perm.RoleId}} ,
@{Name = "Path" ; Expression = {$path}}

}
}
else{
$report += $perm | Select @{Name = "Virtual Machine" ; Expression = {$Path.name}},
@{Name = "User/Group" ; Expression = {$perm.Principal}} ,
@{Name = "Role" ; Expression = {$roleshttp://$perm.RoleId}}


}
}
}


$report | ConvertTo-HTML -head $a -body "<H2>Virtual Machine Permissions</H2>" | Out-File $htmlfile


What would be the variable for the VM name that goes in the brackets below?


@{Name = "Virtual Machine" ; Expression = {}}


I've tried a few things but can't get the VIrtual Machine column to populate with the VM names.

Thanks
Logged
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #1 on: September 27, 2009, 07:49:20 PM »

try $parent.Name
Logged
aflora
Newbie
*
Posts: 16


View Profile
« Reply #2 on: October 02, 2009, 01:52:38 PM »

This works {(Get-View -Id $perm.Entity).Name}}

Thanks anyway
Logged
Pages: [1]
Print
Jump to: