title: Loop a script every x seconds
body: <p>What can I put around my code to make it loop automatically every x seconds, but if the script is cancelled by CTRL+C, to have it ask for input again?</p>
  
  <pre><code>    mode con: cols=40 lines=5
      while ($tag -ne "Q"){
      $tag1 = ""
      while (-not ($tag1)) {
      $tag1 = Read-Host 'Enter tag #, IP, or Q to quit'
      }
      if($tag1 -eq "Q"){break}
  
      $ErrorActionPreference = 'silentlycontinue'
  
          mode con: cols=80 lines=53
  
      cls
  
          sc.exe \\$tag1 start RemoteRegistry;
  
      cls
  
          start-sleep -seconds 2
  *-Need Loop here-*      
      cls
  
          $CompInfo = get-wmiobject -class win32_computersystem -computername $tag1;
          $username = $CompInfo.UserName.Split("\")[1]; #Outputs DOMAIN\USER into an array and selects USER to display
          $fullname = ((net user $username /domain | Select-String "Full Name") -replace "Full Name","").Trim(); #Takes the USER and displays the full name
  
          #get-wmiobject -class win32_computersystem -computername c73118 | format-table -Property @{Name="DOMAIN\user";Expression={$_.username}} --&gt; Get w/o variable
  
          $CompInfo `
          | Format-Table -Autosize -Property `
              @{ Name = "DOMAIN\user"; Expression = { $_.username } },
              @{ Name = "Full Name"; Expression = { $fullname } };
      }
  </code></pre>