I have the following problem with my powershell script. With MemberOf I d'ont see all groups. I think the output is too long for the field.....

How can I resolve this problem? Any Help is welcome......

This is my script:

import-module activedirectory

get-aduser -filter {(company -eq "abc") -and (Enabled -eq $false)} -properties * | select company, samAccountName, MemberOf | Format-List

1 Answer 1


If you just want to expand MemberOf

get-aduser -filter {(company -eq "abc") -and (Enabled -eq $false)} -properties * | select -expandproperty MemberOf

Example 2 in the link below uses this method. https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/select-object?f=255&MSPPError=-2147217396

Edited after below comments asking about foreach loop.

get-aduser -filter {(company -eq "abc") -and (Enabled -eq $false)} -properties * |
foreach {
    $props = [ordered]@{company = $($_.company)
                        samAccountName = $($_.samAccountName)
                        memberOf = $_ | select-object -ExpandProperty MemberOf
                       } #end props

    new-object -TypeName psobject -Property $props | format-list

} #end foreach

Hope this helps,

Thanks, Tim.

  • No worries. I thought you might be looking for that too. :) To do that, you will need to use a foreach loop. It gets a bit more complicated, you have to create a new object. itknowledgeexchange.techtarget.com/powershell/multiple-expands is a good example.
    – Tim Haintz
    Nov 25, 2016 at 8:58
  • yes exactly, I have to do this with a foreach loop.......but I have no ideas how to do that......I will study your link........
    – dj-dali
    Nov 25, 2016 at 9:07
  • If I get a chance, I will update my original answer with the foreach section.
    – Tim Haintz
    Nov 25, 2016 at 9:56
  • thanks a lot.....looks great......where I have to put -join',' in the script?? I want to see all groups.....
    – dj-dali
    Nov 25, 2016 at 12:07
  • Hi Dj, all the groups are in the script. They are all in the memberOf section, which is the bit that is expanded. If a user is in more than one group, the memberOf section has all of the members in it. You can change the | format-list at the end to change to an output that you would rather. All groups do get expanded though. Thanks, Tim.
    – Tim Haintz
    Nov 27, 2016 at 10:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.