Continuous loop

Hello again,

I have created a task schedule to check DBA is always logged on. This is at 5 minute intervals. I am thinking a contiuous loop would work better and be less intensive. 

 

for(;;)

{{ $i ; $i++

 }

I tried this loop but whenever i pass If parameters it fails.

Would love to hear some ideas?

 

Parents
No Data
Reply
  • What your missing is the function to create the loop.

    this work with a txt file with hostnames of IPs in the C:\temp. 

    Start-Transcript -path C:/temp/PingLog.txt -Append

    $names = Get-Content -Path "C:\temp\Phones.txt"
    function pinger {
    foreach ($name in $names){
    if (Test-Connection -ComputerName $name -Count 1 -ErrorAction SilentlyContinue){
    $Time = Get-Date
    Write-Host "$name,up,$Time" $date -ForegroundColor Green

    }
    else{
    $Time = Get-Date
    Write-Host "$name,down,$Time" -ForegroundColor Red

    }

    }
    pinger
    }

    pinger

Children
No Data