Don’t do that: The following code is creating an endless loop to ping a server.
1 2 3 4 5 6 |
for ($i = 1; $i -lt 100000000; $i++) { $date = Get-Date $ping = Test-Connection -ComputerName $computer -Quiet Write-Host -Object "$date : $ping" } |
Do that: Another way to create an endless loop (using a for loop with empty initialization, condition, and afterthought).
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Solution 1 while ($true) { "$(Get-Date) - $(Test-Connection -ComputerName $computer -Quiet)" } # Solution 2 for ( ; ; ) { "$(Get-Date) - $(Test-Connection -ComputerName $computer -Quiet)" } |
Note: The parameter -Quiet returns a boolean value (True/False).