locked
how to store the group objects count value in a variable in powershell RRS feed

  • Question

  • Hi Folks,

    how to store the group objects count value in a variable in <g class="gr_ gr_12 gr-alert gr_spell gr_inline_cards gr_disable_anim_appear ContextualSpelling ins-del multiReplace" data-gr-id="12" id="12">powershell</g>.

    Example.

    PS C:\> 1,2,3,1,2,1 | group

    Count Name                      Group
    ----- ----                      -----
        3 1                         {1, 1, 1}
        2 2                         {2, 2}
        1 3                         {3}

    How to store the Count value that is 3 in a variable?

    Thanks

    Badal B

    • Moved by Bill_Stewart Wednesday, May 30, 2018 8:49 PM Unanswerable drive-by question
    Wednesday, April 11, 2018 12:41 AM

All replies

  • $count= (1,2,3,1,2,1 | group).Count

    \_(ツ)_/

    Wednesday, April 11, 2018 1:01 AM
  • As an array with all the values for "count":

    $array = 1,2,3,1,2,1 | group | foreach { $_.Count }


    • Edited by TobyU Wednesday, April 11, 2018 6:28 AM
    Wednesday, April 11, 2018 6:28 AM