Sort result of Get-AdgroupMember according to Title

Welcome Forums General PowerShell Q&A Sort result of Get-AdgroupMember according to Title

This topic contains 8 replies, has 3 voices, and was last updated by

 
Participant
1 week, 3 days ago.

  • Author
    Posts
  • #128196

    Participant
    Points: 19
    Rank: Member

    it is only sorting by name not by title.

    My Script

    $TamGroup = Get-AdgroupMember -identity ITDept -Recursive | Sort-Object -property name
    foreach ($member in $TamGroup) { get-aduser $member.samaccountname -properties displayname, title, Department, Office | select displayname, title, Department, Office }

  • #128218

    Moderator
    Points: 174
    Team MemberHelping Hand
    Rank: Participant
    Get-ADGroupMember ITDept -Recursive | Get-ADUser -Properties displayname, title, Department, Office| Sort-Object Title | Select-Object Displayname, Title, Department, Office
    
  • #128232

    Participant
    Points: 885
    Helping Hand
    Rank: Major Contributor

    Sort object takes arrays of properties, Sort-Object -Property Title,Name

  • #128238

    Moderator
    Points: 174
    Team MemberHelping Hand
    Rank: Participant

    kvprassoon is correct, I needed to read the question again.

    Get-ADGroupMember ITDept -Recursive | 
    Get-ADUser -Properties displayname, Title, Department, Office | 
    Sort-Object -Property Title, Name | 
    Select-Object Displayname, Title, Department, Office
    
  • #128347

    Participant
    Points: 19
    Rank: Member

    Get-ADGroupMember ITDept -Recursive |
    Get-ADUser -Properties displayname, Title, Department, Office |
    Sort-Object -Property Title, Name |
    Select-Object Displayname, Title, Department, Office

    The input object cannot be bound to any parameters for the command either because the command does not take pipeline input or the input and its properties do not match
    any of the parameters that take pipeline input.
    + CategoryInfo : InvalidArgument:

    AND

    Same Result of following command, No Sorting
    $TamGroup = Get-AdgroupMember -identity ITDept -Recursive
    foreach ($member in $TamGroup) { get-aduser $member.samaccountname -properties displayname, title, Department, Office | Sort-Object -Property Title, Name | select displayname, title, Department, Office }

     

     

  • #128356

    Participant
    Points: 885
    Helping Hand
    Rank: Major Contributor

    For the second approach in your above reply, You are sorting by Title and Name but selecting DisplayName and title !

  • #128361

    Participant
    Points: 19
    Rank: Member

    i tried this,

    $TamGroup = Get-AdgroupMember -identity ITDept -Recursive
    foreach ($member in $TamGroup) { get-aduser $member.samaccountname -properties name, title, Department, Office | Sort-Object -Property name | select name, title, Department, Office }

    and this also

    $TamGroup = Get-AdgroupMember -identity ITDept -Recursive
    foreach ($member in $TamGroup) { get-aduser $member.samaccountname -properties name, title, Department, Office | Sort-Object -Property title | select name, title, Department, Office }

    but still same result, No Sorting

  • #128364

    Participant
    Points: 19
    Rank: Member

    Sort only happening on name with following

    $TamGroup = Get-AdgroupMember -identity ITDept -Recursive | Sort-Object -Property name
    foreach ($member in $TamGroup) { get-aduser $member.samaccountname -properties name, title, Department, Office | select name, title, Department, Office }

  • #128365

    Participant
    Points: 885
    Helping Hand
    Rank: Major Contributor

    Please check the replies properly,

    If you want to sort by multiple properties, you have to pass those properties to Sort-Object cmdlet. Both of the above approaches Sort only with name not with title. Please check our previous replies.

You must be logged in to reply to this topic.