Changing table values... is it possible?

This topic contains 2 replies, has 2 voices, and was last updated by  Vandrey Trindade 3 years, 9 months ago.

  • Author
    Posts
  • #12843

    Vandrey Trindade
    Participant

    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?

  • #12849

    Dave Wyatt
    Moderator

    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'
    }
    
  • #12854

    Vandrey Trindade
    Participant

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

    Worked like a charm =]

You must be logged in to reply to this topic.