Hi,
Could you please help me with some problem:
for array that contains for instance 97 items I'd like for each 10 items of array do something and then continue with next 10 items after previous "do something" is finished so it could looks like:
cycle {
for each 0..9 items in array1
{ do this }
for each 10..19
{ do same}
}
Do you have any hints how to do it ?
Thank you.
ForEach bunch of items
Forum rules
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Do not post any licensing information in this forum.
Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
Re: ForEach bunch of items
Loop-d-loop!
PowerShell Code
Double-click the code block to select all.for($i=1; $i -le 10; $i++){ Write-Host "Block:$i" -fore green for($j=1;$j -le 10; $j++){ Write-Host "`tSUB:$j" -fore red } }
Re: ForEach bunch of items
No, this is not what I needed to achieve. Your first code will display only each 10 item of array so result will be:
0
10
20
30
40
50
60
70
80
90
but I need to take all 10 items between 0-10 and display them, then 11-20 etc., so result should be:
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
etc.
Also second code didn't help as it always take all items from array not only part of.
0
10
20
30
40
50
60
70
80
90
but I need to take all 10 items between 0-10 and display them, then 11-20 etc., so result should be:
0 1 2 3 4 5 6 7 8 9
10 11 12 13 14 15 16 17 18 19
etc.
Also second code didn't help as it always take all items from array not only part of.
Re: ForEach bunch of items
This one goes sideways if that is what you want;
PowerShell Code
Double-click the code block to select all.$bailout=97 for($i=1; $i -le 10; $i++){ Write-Host "$i " -fore red -back white -NoNewLine for($j=1;$j -le 10; $j++){ if($bailout -eq 0){break} $bailout-- Write-Host "$bailout " -fore black -back white -NoNewLine } }
Re: ForEach bunch of items
I still cannot quite understand what you are asking. Here is one that goes sideways in groups of 10:
We can also read files in groups of lines.
PowerShell Code
Double-click the code block to select all.$bailout=0 for($i=1; $i -le 10; $i++){ Write-Host "`n" -fore red -back white -NoNewLine for($j=1;$j -le 10; $j++){ if($bailout -ge 97){break} $bailout++ Write-Host "$bailout " -fore black -back white -NoNewLine } } Write-HostBasically to count is groups you need embedded loops. What you do with the is very much dependent on what you are trying to do.
We can also read files in groups of lines.
Re: ForEach bunch of items
Yes,
this is exactly what I want to achieve. Take always 10 computers from some pool(array of computers), do something with them(reboot or ping them) and then move to next set of 10 computers. If there is a remainder of division(87/10 - remainder is 7), then take this remain computers and do the same.
I think your third code is appropriate for this.
Thank you very much...
this is exactly what I want to achieve. Take always 10 computers from some pool(array of computers), do something with them(reboot or ping them) and then move to next set of 10 computers. If there is a remainder of division(87/10 - remainder is 7), then take this remain computers and do the same.
I think your third code is appropriate for this.
Thank you very much...