Newbie to PS asking a newbie question

This topic contains 8 replies, has 5 voices, and was last updated by Profile photo of Drew Stallcop Drew Stallcop 6 months, 1 week ago.

  • Author
    Posts
  • #41506
    Profile photo of Rich Whyrick
    Rich Whyrick
    Participant

    Hello, all. This is probably not worth asking, but it's more out of curiosity than anything. I'm running a very simple script to output users in a group. Obviously I can dump it to Excel and sort it very easily, but is there a way to sort it if I output to the screen?

    Get-ADGroupMember -Identity group_name | select-object samaccountname

    I apologize in advance if this is a ridiculous question I should be able to figure out on my own.

    Loving this site!

    Thanks.
    Rich

  • #41517
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    That's what the Sort-Object cmdlet does. For example:

    Get-ADGroupMember -Identity group_name |
    Select-Object -Property SamAccountName |
    Sort-Object -Property SamAccountName
    
  • #41519
    Profile photo of Rich Whyrick
    Rich Whyrick
    Participant

    I feel really dumb asking that now that I see how easy it was.

    Thank you, Dave.

  • #41521
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    No worries! 🙂 The *-Object commands are generally very useful. They give you a sort of query language that you can use on anything:

    Where-Object
    Select-Object
    Group-Object
    Sort-Object
    ForEach-Object

    With those 5 commands, you can do some really powerful stuff. 🙂

  • #41523
    Profile photo of Rich Whyrick
    Rich Whyrick
    Participant

    Sweet! That's rocking stuff.

    Thanks, Dave!

    • #41537
      Profile photo of Mystic pl
      Mystic pl
      Participant

      You can also pipe it to GridView, its a nice tool worth trying.

      Get-ADGroupMember -Identity group_name | select-object samaccountname | Out-GridView

  • #41548
    Profile photo of Don Jones
    Don Jones
    Keymaster

    As a way of teaching you to fish ;), I'd have done:

    help *sort*
    

    Or

    Get-Command *sort*
    

    To discover Sort-Object.

  • #41560
    Profile photo of Rich Whyrick
    Rich Whyrick
    Participant

    I appreciate all the feedback, everyone. I'm learning by leaps and bounds!

    Thank you.

  • #41650
    Profile photo of Drew Stallcop
    Drew Stallcop
    Participant

    Thanks for teaching us to fish... it's obvious, but in the heat of things it's sometimes easy to forget the simple way to find something.

You must be logged in to reply to this topic.