Round-Robin a list for home drive creation

Welcome Forums General PowerShell Q&A Round-Robin a list for home drive creation

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

2 years, 2 months ago.

  • Author
  • #61620

    Points: 0
    Rank: Member

    Hi, i'm just looking for ideas on how to better utilize powershell to create a round-robin list to create home drives.

    I was thinking about creating an array and then writing the array object number to a file as a tracker and then just grabbing the next number in the list.

    Any thoughts?

  • #61632

    Points: 639
    Helping Hand
    Rank: Major Contributor

    There are alot of ways to do things. If you don't need perfect balance, you can use Get-Random

    $shares = "Server1", "Server2", "Server3"
    $usingShare = $shares | Get-Random -Count 1
    "Using share {0}" -f $usingShare

    Otherwise, you could use Get-ChildItem to to get a count of shares per server and choose a server that has the least shares.

    • #61689

      Points: 0
      Rank: Member

      I was looking for perfect balance. I like the get-random idea, but I was more thinking sequencially 0-11 in the array.

      I was using this

      [int]$n = gc C:\Powershell\HD\hd_rr.txt -ea "silentlycontinue" | Select -last 1 
      write-host $n
      if ($n -eq 11) {
      new-item C:\Powershell\HD\hd_rr.txt -itemtype File -force 
      [int]$hd = 0
      } else {
      write-host "second"
      [int]$hd = $n + 1
      write-host $hd
      ac -path C:\Powershell\HD\hd_rr.txt -value $hd
      $indexnumber = $hd

      My starter file has an entry of 0

  • #61699

    Points: 364
    Helping Hand
    Rank: Contributor

    Yes, if all you want to do is run it sequencially then all you need is the logging of the last number.

    If I use Rob's example of the shares variable.
    You could just call each specific share/whatever-data-you-store by it's index number.


    Will get you "Server1"
    If you replace the number with a variable.


    You would then call the share/folder/whatever information that is stored with that index number.
    Replacing the content of $n wherever you are in the sequence.

  • #61707

    Points: 639
    Helping Hand
    Rank: Major Contributor

    If you really want balance, the best approach is determining the number of folders that exist in the share on each server. Using an index still assumes that no one or nothing else will create folders in the share location. It will take longer to execute, but it's the best method to ensure balance.

The topic ‘Round-Robin a list for home drive creation’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort