Author Posts

January 10, 2017 at 2:24 pm

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?

January 10, 2017 at 3:12 pm

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.

January 11, 2017 at 12:03 pm

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

January 11, 2017 at 2:51 pm

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.

January 11, 2017 at 3:36 pm

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.