Hello Steve,
This is just a difference in the way we are running things. To run this as a self contained script you have to put the function definition first. You are currently getting the error because Powershell does not know about Get-Path until after it tries to use it in the Select-Object.
If you find the Get-Path function useful in general practice you can add it to your Powershell profile script and it will always be there. That is probably why esarakaitis is not having any issues.
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}}
}