Separating values into groups

Welcome Forums General PowerShell Q&A Separating values into groups

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

 
Participant
3 months, 3 weeks ago.

  • Author
    Posts
  • #105136

    Participant
    Points: 35
    Rank: Member

    I've got a list of servernames, database names and database sizes that I want to sort into two groups based on size, alternating between group 1 and group 2. So, biggest in gp1, 2nd biggest in gp2, 3rd biggest in gp1 and 4th biggest in gp 2...etc.
    How can I do that?

    SqlServerInstance  	DatabaseName 	Size(MB)
    SRV1	DB1	1000
    SRV2	DB2	999
    SRV1	DB3	998
    SRV2	DB1	888
    SRV1	DB7	675
    SRV2	DB9	501
    SRV1	DB15	475
    
  • #105137

    Participant
    Points: 154
    Helping Hand
    Rank: Participant

    So you want to distribute a group of items evenly to another group of items? The items are different but the underlying problem is the same:

    distribute computers across several groups for wsus using powershell

    • #105236

      Participant
      Points: 35
      Rank: Member

      Olaf, yep, that did it, thank you. I appreciate the help

      $Groups = @("1","2")
      $GroupLists = @{}
      $Count = 0
      $list | % {
      $Name = $Groups[$Count % $Groups.Count]
      $GroupLists[$Name] += @($_)
      $Count++
      }
      
      $GroupLists['1'] 
      $GroupLists['2'] 
      

The topic ‘Separating values into groups’ is closed to new replies.