title: Powershell Invoke-Sqlcmd restarts the scripts from the beginning after an error
body: <p>I have a <code>.sql</code> file which is similar to the below</p>
  
  <pre><code>BEGIN TRY
     PRINT 'Loading master data....'
     BEGIN TRANSACTION
  
     -- Some Insert scripts
     -- COPY Settings from DBOne to DBTwo
  
     PRINT 'Copy Settings Started...'
     INSERT INTO DBTWO.dbo.SETTINGS
     (Id,
      Code,
      Name)
     SELECT Id,Code,Name FROM DBONE.dbo.SETTINGS
     EXCEPT
     SELECT Id,Code,Name FROM DBTWO.dbo.SETTINGS
  
     PRINT 'Copy Settings completed...'
  
     COMMIT
  END TRY
  BEGIN CATCH
     ROLLBACK
  END CATCH
  </code></pre>
  
  <p>I am invoking the sql script with the following powershell command</p>
  
  <p><code>Invoke-Sqlcmd -ServerInstance ".\" -InputFile ".\Insert_Script.sql"  -Verbose</code></p>
  
  <p>During testing of the script I observed that after printing the text 'Copy Settings Started...' the script started again from the beginning and I see the print statements in the beginning of the file appears again, and when the control reaches the INSERT INTO..EXCEPT, it failed with the timeout exception. </p>
  
  <p>Later I identified that the table 'DBTWO.dbo.SETTINGS' does not exist, and after creating the table the script executed successfully without any issues.</p>
  
  <p>But the question is, why the script restarted again from the beginning and failed at the same place during the second run. At this stage I even checked the sp_who2 and that showed a deadlock, both the victim and the culprit are the same script block. So, with all this explanations, the question remains unanswered is 'why the script started again?'</p>
  
  <p>Could someone please provide a better reasons for this behavior.</p>