I've done quite a bit of searching but can't seem to find an answer to this, but if it has been answered, I apologize, and just link me to it if you can.
What I'm trying to do is distribute files across 6 different paths based on which path currently has the least number of files in it.
What I thought to do is to add the responses from these ($Queue1-6 are just file paths) to an array and then sort them and get the path from the first object.
$QueueFiles1 = ( Get-ChildItem $Queue1 | Measure-Object ).Count
$QueueFiles2 = ( Get-ChildItem $Queue2 | Measure-Object ).Count
$QueueFiles3 = ( Get-ChildItem $Queue3 | Measure-Object ).Count
$QueueFiles4 = ( Get-ChildItem $Queue4 | Measure-Object ).Count
$QueueFiles5 = ( Get-ChildItem $Queue5 | Measure-Object ).Count
$QueueFiles6 = ( Get-ChildItem $Queue6 | Measure-Object ).Count
$FileNumArray = @($QueueFiles1, $QueueFiles2, $QueueFiles3, $QueueFiles4, $QueueFiles5, $QueueFiles6)
$FileNumArray = $FileNumArray | Sort-Object
The problem is (as far as I can tell) that after adding these values to the array, the object is lost and all that is left is the value, so now I don't know how to reference back to the original object to obtain the path information.
Any thoughts on how to do this would be appreciated and it doesn't need to be done with an array, like this, if there's an easier way to compare those file count values and obtain the path information of the lowest value.
Also, if there is more than 1 path with the lowest value, it doesn't matter which is returned.
Thanks in advance for any assistance.
$QueueFiles1 = ( Get-ChildItem $Queue1 | Measure-Object ).Countall you are capturing is the count. The is no object assigned here. I am building an answer using hash tables.