emnt
emnt

Reputation: 25

Powershell Do Loop

I'm new at powershell and i need some help to end my code. Everything is ok but i need on ELSE go back to DO doing a loop. How can i solve this?

  DO {
      $getinfo=Get-Content $wblogpath | Select-Object -last 1 
      Write-Host -NoNewline "."$counter
      Start-Sleep -s 1
      $counter++
     }
  WHILE ($getinfo -notlike '*ReadyToRun->Run*' -and 
         $getinfo -notlike '*test*' -and
         $getinfo -notlike '*error*' -and
         $counter -le 8)

  IF ($getinfo -like '*ReadyToRun->Run*')
      {
       Write-Host "`nREADY TO RUN"
      }
  ELSEIF ($getinfo -like '*test*') 
      {
       Write-Host "`ntest"
      }
  ELSEIF ($getinfo -like '*error*') 
      {
       Write-Host "`nerror"
      }
  ELSE{
       Write-Host "`nRESTARTing WINBASIS"
       $counter=0
      }

Thanks :)

Upvotes: 0

Views: 154

Answers (2)

TessellatingHeckler
TessellatingHeckler

Reputation: 29048

Simply wrap all your code in another loop.

DO {

    #your code here#

} WHILE ($true)

Upvotes: 1

Esperento57
Esperento57

Reputation: 17492

with recursive method

     function myfunction()
     {
     DO {
           $wblogpath="C:\temp\test.csv"
           $getinfo=Get-Content $wblogpath | Select-Object -last 1 
           Write-Host -NoNewline "."$counter
           Start-Sleep -s 1
           $counter++
          }
       WHILE ($getinfo -notlike '*ReadyToRun->Run*' -and 
              $getinfo -notlike '*test*' -and
              $getinfo -notlike '*error*' -and
              $counter -le 8)

       IF ($getinfo -like '*ReadyToRun->Run*')
           {
            Write-Host "`nREADY TO RUN"
           }
       ELSEIF ($getinfo -like '*test*') 
           {
            Write-Host "`ntest"
           }
       ELSEIF ($getinfo -like '*error*') 
           {
            Write-Host "`nerror"
           }
       ELSE{
            Write-Host "`nRESTARTing WINBASIS"
            $counter=0
            myfunction
           }
     }

     myfunction

Upvotes: 1

Related Questions