Get-Aduser memberOf RRS feed

  • Question

  • Hello,

    I have a script to export user's groups but in the list I see only a few and than "..."

    script is


      Import-Module ActiveDirectory

       Remove-Item C:\scripts\export.txt
       $csvreportfile = "C:\scripts\export.txt"

       $content = get-content C:\scripts\import.txt

       foreach ($line in $content)
        Get-ADUser  -filter { (employeeID -eq $line) } -SearchBase $OU  -Properties *  |    
        Select-Object @{Label = "First Name";Expression = {$_.GivenName}}, 
                            @{Label = "Last Name";Expression = {$_.Surname}},
                            @{Label = "Display Name";Expression = {$_.DisplayName}},
                            @{Label = "Logon Name";Expression = {$_.sAMAccountName}},
                            @{Label = "Emp. ID";Expression = {$_.employeeID  }},
                            @{Label = "Memeber of";Expression = {$_.memberOf -match "XXX"  -replace ",XXXXXXXXX", "" -replace    "CN=", "" -replace ",XXXXX", "" -replace ",,XXXX", "" }} |
          Out-File -Append -FilePath $csvreportfile -Encoding UTF8 

    and the result is

    First Name   : XXXX
    Last Name    : XXXXX
    Display Name : XXXXX
    Logon Name   : XXXX
    Emp. ID      : XXX
    Memeber of   : {XXXX, XXXXX, XXXXX, XXXXX...}

    I don't know why I see only first four groups and not all groups.

    Can you please help me with it?

    Thanks a lot


    • Moved by Bill_Stewart Tuesday, July 18, 2017 2:51 PM Piping to Out-String is not a good answer
    Thursday, June 15, 2017 7:46 AM

All replies

  • Out-File -Width 180

    help Out-File -Full


    Thursday, June 15, 2017 8:19 AM
  • thanks, but user is member of 10 groups and in the export file I see only 4 and than "...".  
    so I don't think this is problem wit out-file
    Thursday, June 15, 2017 9:03 AM
  • MemberOf is an array and must be expanded in order to be seen correctly.  There is no automatic conversion of an array to a string in output.  You will have to  convert the array to something that can be saved to a file.

    In the Gallery are scripts that will do what you are trying to do and they are already designed to handle this issue.  Look in the Gallery for a script that does what you are trying to do.


    Thursday, June 15, 2017 9:10 AM
  • So I added into end of memberOF line | Out-String and it works good now.

    Thanks for help


    Thursday, June 15, 2017 10:22 AM