Pages: [1]
Print
Author Topic: Error when running permissions script  (Read 1193 times)
aflora
Newbie
*
Posts: 16


View Profile
« on: October 01, 2009, 06:43:33 PM »

Hi

I get the following error when I run the permissions script:

"Method invocation failed because [System.Management.Automation.PSObject] doesn't contain a method named 'op_Addition'."

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
  $report =+  $permission | Select-Object @{Name="Principal"; Expression={$permission.Principal}},
                                @{Name="RoleName"; Expression={$roleName}},
                                @{Name="Object"; Expression={Get-Path $entityView}}
}

$report | Convert-HTML | Out-File D:\perms.htm

« Last Edit: October 01, 2009, 06:56:07 PM by aflora » Logged
aflora
Newbie
*
Posts: 16


View Profile
« Reply #1 on: October 01, 2009, 06:57:28 PM »

I think I figured out my own issue. I forgot:

$report = @()

Doh!
Logged
esarakaitis
Administrator
Sr. Member
*****
Posts: 256


8223109 sack57@hotmail.com littleking57 rootinfortwayne
View Profile WWW Email
« Reply #2 on: October 04, 2009, 08:07:32 PM »

ahh, yes! you must create the empty array first Smiley
Logged
Pages: [1]
Print
Jump to: