Pages: [1]
Print
Author Topic: List permissions Per VM  (Read 910 times)
sigmanumk92
Newbie
*
Posts: 5


View Profile Email
« on: January 03, 2010, 05:49:12 PM »

I saw on here the script which will get user permissions from virtual center.  I am a noob to scripting and i would like to be able to use that script to get the permissions per vm.  Is there a way to do that?


* PUAReport.ps1 (1.01 KB - downloaded 64 times.)
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #1 on: January 04, 2010, 08:26:26 AM »

i guess what are you asking?

Code:
get-vipermission

along with the script that you posted, will list all assigned permissions and what level they have been assigned at.

what else do you want?


Logged
sigmanumk92
Newbie
*
Posts: 5


View Profile Email
« Reply #2 on: January 04, 2010, 08:33:10 AM »

Thanks!

I ran the get-vipermission but i wanna be able to get the actual name of the folder, like admin, it.  It just shows under the EntityID somthing like this, shows folder-group-d1.  Is there a way to map that to the actual name of the folder?

EntityId             Role

--------             ----
Datacenter-datace... GAI Power User
Datacenter-datace... ReadOnly
Datacenter-datace... GAI VM ConsoleOnly Use...
Datacenter-datace... GAI VM ConsoleOnly Use...
Datacenter-datace... GAI VM ConsoleOnly Use...
Datacenter-datace... GAI VM ConsoleOnly Use...
Datacenter-datace... ReadOnly
Datacenter-datace... GAI Administrators
Datacenter-datace... GAI VM ConsoleOnly Use...
Datacenter-datace... GAI Storage Admins
Datacenter-datace... GAI Read-only
Datacenter-datace... GAI VM ConsoleOnly Use...
Datacenter-datace... GAI VM ConsoleOnly Use...
Datacenter-datace... GAI VM ConsoleOnly Use...
Datacenter-datace... GAI Storage Admins
Datacenter-datace... GAI Power User
Datacenter-datace... GAI Power User
ClusterComputeRes... GAI Administrators
Folder-group-d1      GAI Power User
Folder-group-d1      GAI Power User
Folder-group-d1      GAI Power User
Folder-group-d1      GAI Power User
Folder-group-d1      GAI Power User
Folder-group-d1      GAI Power User
Folder-group-d1      GAI Power User
Folder-group-d1      GAI Power User
Folder-group-d1      GAI Power User
Folder-group-d1      GAI Power User
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #3 on: January 04, 2010, 08:36:30 AM »

yep, using this:

Code:
Function Get-Path($entity){
$path = $entity.Name
while($entity.Parent -ne $null){
$entity = Get-View -Id $entity.Parent
if($entity.Name -ne "vm" -and $entity.Name -ne "host"){
$path = $entity.Name + "\" + $path
}
}
$path
}

$si = Get-View ServiceInstance
    $am = Get-View $si.Content.AuthorizationManager

    $roleList = $am.RoleList

    # Create the role map
    $roleMap = @{}
    # Add the roles to the map
    foreach ($role in $roleList)
    {
        $roleMap[$role.RoleId] = $role
    }

    $permissions = $am.RetrieveAllPermissions()
    # Foreach permission
    foreach ($permission in $permissions)
    {
        $roleName = $roleMap[$permission.RoleId].Name
        $entityView = Get-View $permission.Entity
        $permission | Select-Object @{Name="Principal"; Expression={$permission.Principal}},
                                    @{Name="RoleName"; Expression={$roleName}},
                                    @{Name="Object"; Expression={Get-Path $entityView}}
    }

Logged
sigmanumk92
Newbie
*
Posts: 5


View Profile Email
« Reply #4 on: January 04, 2010, 08:47:22 AM »

That worked, your a genius.   Smiley
Logged
sigmanumk92
Newbie
*
Posts: 5


View Profile Email
« Reply #5 on: January 04, 2010, 09:31:42 AM »

Ok one more question....is there a way to list all the vms under each folder.
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #6 on: January 04, 2010, 02:42:32 PM »

Code:
foreach ($folder in get-folder)
    {
    foreach ($vmachine in $folder | get-vm)
        {
    "" | select @{Name = "Folder"; Expression = {$folder.name}}, @{Name = "VM"; Expression = {$vmachine.name}}
        }
    }
Logged
esarakaitis
Administrator
Full Member
*****
Posts: 241


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #7 on: January 04, 2010, 11:14:26 PM »

^^ did that code work for you?
Logged
sigmanumk92
Newbie
*
Posts: 5


View Profile Email
« Reply #8 on: January 05, 2010, 08:30:21 AM »

yep that worked!  i just got a chance to try it out.
Logged
Pages: [1]
Print
Jump to: