powershell - While loop inside another while loop not re-reading inner while loop -
i have 2 while loops, 1 within other, iterate on 2 different datasets , want outer while loop's first row info loop through rows in inner while loop looking match , if not, move onto sec row in outer loop, 1 time again looping through records in inner while loop. however, after first outer loop's record has looped through records in inner loop, sec row in outer loop not loop through records in inner loop; it's if first effort @ going through records in inner loop did not reset beginning! here code - can tell me going wrong?
$pgconnstring = "select pgname table1" $msconnstring = "select msname table2"; $pgdbconn = createdbconnection "postgres"; $pgdbcmd = createdbcommand $pgconnstring $pgdbconn; $pgreaderoutput = $pgdbcmd.executereader(); $msdbconn = createdbconnection "mssql"; $msdbcmd = createdbcommand $msconnstring $msdbconn; $msreaderoutput = $msdbcmd.executereader(); while ($pgreaderoutput.read()) { $reportername = $pgreaderoutput.getvalue(0); write-output "current reporter is: $reportername"; while ($msreaderoutput.read()) { $currmsrec = $msreaderoutput.getvalue(0); write-output "current sql record is: $currmsrec"; if($currmsrec -eq $reportername) { $match = 1 write-output "matched" } else { write-output "no matched" $match = 0; } } if($match -eq 1) { write-output "the reporter: $reportername has not been sent email; send them one!"; } }
in inner loop go through elements returned $msreaderoutput.read(). when inner loop done first time, don't alter $msreaderoutput in outer loop, there can't perchance more elements next time process it.
i assume want reset $msreaderoutput object before each inner loop starts, can start iterating on again.
powershell while-loop
No comments:
Post a Comment