Value is stored in array before it should be


hi code work in progress, i'm trying copy file file server machine 1. once finishes copy machine 1 , server. keep going , exponential grow each time.

the problem i'm having i've declared array , values being stored in before should be.

$computers = @() $computers += list of coputers $array2 = @() $i=0  :outer for($i;$i -lt $computers.length; $i++){     $completeinner = $false     $maincopy = start-job{copy-item "c:\users\cody-horton\desktop\test.txt" "\\$($computers[$i])\c`$" -recurse -force}     write-host $array2[0]     if($array2.count -gt 0){         foreach($computer in $array2){             if($computers.count -lt ($computers.count+1)){                 $jobarray = @()                 $jobarray += start-job{copy-item -path "c:\users\cody-horton\desktop\test.txt" -destination "\\$($computers[$i+1])\c`$" -recurse -force}                 $i = $i++             }else{                 break outer             }         }     }     while(-not $completeinner){         $inprogress = $jobarray | where-object {$_.state -match 'running'}         if(-not $inprogress){             $completeinner = $true          }     }     wait-job -job $maincopy     $array2 += $computers[$i] }

the check if array greater 0 passes because says there computer in array though there shouldn't be. somehow code $array2 += $computers[$1] being executed before check though isn't far down in loop.

i have no idea why happening maybe i'm overlooking appreciated! thanks!


okay reason $1=0 being outside of loop parameters messing up. put in loop , doesn't jump $array2+=$computers[$i]. i'll post finished code here. thanks.


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Edit Group Policy

Hyper-V VM not reaching OS 'Logon' screen

DNS question...