Specifies the number of seconds before the queries time out. If a timeout value is not specified, the queries do not time out. The timeout must be an integer between 1 and 65535.
A simpler repro scenario for QueryTimeout.
PS C:\Users\atushar> Invoke-Sqlcmd -Query "waitfor delay '00:00:31'" -Database master -ServerInstance localhost
Invoke-Sqlcmd : Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
At line:1 char:14
+ Invoke-Sqlcmd <<<< -Query "waitfor delay '00:00:31'" -Database master -ServerInstance localhost
+ CategoryInfo : InvalidOperation: (:) [Invoke-Sqlcmd], SqlPowerShellSqlExecutionException
+ FullyQualifiedErrorId : SqlError,Microsoft.SqlServer.Management.PowerShell.GetScriptCommand
Also few more defects that are found by John from PS team. Thanks John.
It does accept a value 0 and does nothing and still defaults to 30 seconds. In addition, it doesn’t limit the max time to 65K ~18 hours but accepts int::maxvalue which is effectively no time out(i.e. ~24k days).