Changing table values... is it possible?

Hi,

I’m trying to get a table and change some values to display for the user.
Something like this:

Original table

Identity Trustee AccessRights


list1 luiz {SendAs}
list1 nayara {SendAs}
list1 adriana {SendAs}
list2 rafael {SendAs}
list2 samuel {SendAs}
list2 sueli {SendAs}
list2 thais {SendAs}

Custom table that I managed to make

Lista/Caixa Usuário Permissão


list1 luiz {SendAs}
list1 nayara {SendAs}
list1 adriana {SendAs}
list2 rafael {SendAs}
list2 samuel {SendAs}
list2 sueli {SendAs}
list2 thais {SendAs}

I’m using the command below to get to this table:

$listas = Get-RecipientPermission | where {($.Trustee -ne ‘nt authority\self’) -and ($.Trustee -ne ‘null sid’)} | select Identity,Trustee,AccessRights | ft @{expression=“Identity”;label=“Lista/Caixa”;width=35},@{expression=“Trustee”;label=“Usuário”},@{Expression=“AccessRights”;label=“Permissão”}

But I need to change that “{SendAs}” for something like “Enviar como”, to make the table look like this:

Custom table needed

Lista/Caixa Usuário Permissão


list1 luiz Enviar como
list1 nayara Enviar como
list1 adriana Enviar como
list2 rafael Enviar como
list2 samuel Enviar como
list2 sueli Enviar como
list2 thais Enviar como

Is it possible?

Yep, it’s possible. The curly braces around {SendAs} indicate that the AccessRights property is an array, and whatever enumerated type is contained in that property will also have other possible values that you’d need to translate. Because it’s an array, you’ll want to use a loop of some sort (probably foreach) to translate each element individually.

Because I’m not sure what type you’re dealing with, I wrote an example to treat everything as strings; you can just add additional values to the $accessRightsTranslations hashtable as needed. This isn’t the most efficient way to go about it, but it does work. Better would be to write a function that works with the enum directly.

$accessRightsTranslations = @{
    'SendAs' = 'Enviar como'
}

Get-RecipientPermission | 
Where-Object { ($_.Trustee -ne 'nt authority\self') -and ($_.Trustee -ne 'null sid') } |
ForEach-Object {
    $permission = $_
              
    $accessRights = @()

    foreach ($right in $permission.AccessRights)
    {
        $rightString = [string]$right

        if ($accessRightsTranslations.ContainsKey($rightString))
        {
            $accessRights += $accessRightsTranslations[$rightString]
        }
        else
        {
            $accessRights += $rightString
        }
    }

    New-Object psobject -Property @{
        'Lista/Caixa' = $permission.Identity
        'Usuário' = $permission.Trustee
        'Permissão' = $accessRights
    } | Select-Object 'Lista/Caixa','Usuário','Permissão'
}

Wow Dave!
Thanks a lot for the quick reply and for helping me!

Worked like a charm =]