I am trying to run tracert command 2 times by using a do loop. I am doing this simply by counting the number of times "Trace complete." shows. So in the script below, I want the loop to run until the variable contains "Trace complete." 2 times. But obviously its not working.
do {
$2+= tracert $ip
} until ( $2.Contains("Trace complete.") -ge 2)
#( $2 | select-string "Trace complete").length -eq 2
I also tried the select string method but both don't result in loop ending until Trace Complete has appeared twice. Any help please?
Edit 1:
I would also like to store the output of tracert in a variable so i can view it