none
Powershell create two colums of data to compare RRS feed

  • Question

  • This is a very basic portion of what I am trying to accomplish. Two users and outputting both users group memberships to a file or the screen or really anything.  I just want to get the data side by side and sorted A to Z. 

    The sorting part I will work on unless you may know a answer already but not concerned about that. The problem is it outputs the group memberships for each user right under each other


    user1

    groups

    groups

    groups

    groups

    user2

    groups

    groups

    groups

    groups

    I am trying to get

    User1                   User2

    groups                 Groups

    I have tried several approaches none with any different results. 

    Thanks and please be kind.


    $ident1="user1"
    $ident2="user2"
    
    $groups1=(Get-ADPrincipalGroupMembership -Identity $ident1).name 
    $groups2=(Get-ADPrincipalGroupMembership -Identity $ident2).name 
    
    
    Write-Output $ident1          $ident2
    
    Write-Output  $Groups1  $Groups2

     

     

    R White



    • Edited by tnetplus Friday, November 21, 2014 3:32 PM
    Friday, November 21, 2014 1:52 PM

Answers

  • This is a sloppy way of getting what you're looking for but it worked in my quick test. There's probably a bunch of ways to do this.

    if ($groups1.length -gt $groups2.length)
    {
        $longer = $groups1
    }
    else
    {
        $longer = $groups2
    }
    
    $hash = @{}
    
    for ($i=0; $i -lt $longer.length; $i++)
    {
        $hash.add($($groups1[$i]),$($groups2[$i]))    
    }
    
    $hash | ft -autosize | out-file "c:\temp\testing.txt"
    #piping into the outfile is optional

    • Marked as answer by tnetplus Friday, November 21, 2014 7:27 PM
    Friday, November 21, 2014 6:19 PM

All replies

  • This is a sloppy way of getting what you're looking for but it worked in my quick test. There's probably a bunch of ways to do this.

    if ($groups1.length -gt $groups2.length)
    {
        $longer = $groups1
    }
    else
    {
        $longer = $groups2
    }
    
    $hash = @{}
    
    for ($i=0; $i -lt $longer.length; $i++)
    {
        $hash.add($($groups1[$i]),$($groups2[$i]))    
    }
    
    $hash | ft -autosize | out-file "c:\temp\testing.txt"
    #piping into the outfile is optional

    • Marked as answer by tnetplus Friday, November 21, 2014 7:27 PM
    Friday, November 21, 2014 6:19 PM
  • This is a sloppy way of getting what you're looking for but it worked in my quick test. There's probably a bunch of ways to do this.

    if ($groups1.length -gt $groups2.length)
    {
        $longer = $groups1
    }
    else
    {
        $longer = $groups2
    }
    
    $hash = @{}
    
    for ($i=0; $i -lt $longer.length; $i++)
    {
        $hash.add($($groups1[$i]),$($groups2[$i]))    
    }
    
    $hash | ft -autosize | out-file "c:\temp\testing.txt"
    #piping into the outfile is optional

    Wow thanks very much.

    That is fancy coding. 

    Again that is very kind of you to help.

    Have a wonderfull holiday.


    R White

    Friday, November 21, 2014 7:28 PM