display two arrays elements use table

Posted on 2011-05-11
Last Modified: 2012-05-11

I created two simple arrays of string
for example:
$users = {"James","Michelle","George","Louis", ...etc}
$manager = {"Sarah","Jessica","Bill","William", ...etc}

for objects in powershell
is possible to use table like
$a = @{Expression={$_.Name};Label="Name";width=50}, `

get-process | Format-able $a

i tried use this with normal array but i can't  figure out how i can do this
i would like to display array elements like this
                      Users                                                   Managers
                   ++++++++                                              +++++++++
                      James                                                   Sarah
                     Michelle                                                 Jessica
                     George                                                   Bill
                       Louis                                                    William

Question by:ang3lus
    LVL 13

    Accepted Solution

    Here you are:

    $users = @("James","Michelle","George","Louis")
    $manager = @("Sarah","Jessica","Bill","William")
    $a = @{Expression={$_.Users};Label="Users";width=50}, @{Expression={$_.Managers};Label="Managers";width=15}
    $users | ForEach-Object {$i=0} {
        New-Object -TypeName PSObject -Property @{
            Users = $_
            Managers = $manager[$i]
    } | Format-Table $a

    Open in new window


    Author Closing Comment

    thanks very much

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Why would I want to create a function for tracking messages? I am glad you asked. As with most monotonous/routine tasks, human error tends to creep in after doing the same task over and over again. By creating a function, you load the function once…
    This article shows how a content item can be identified directly or through translation of a navigation type. It then shows how this information can be used to create a menu for further navigation.
    Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now