There is also the parameter -ConnectionTimeout which can be set for example to the same value as the -QueryTimeout parameter. For me ConnectionTimeout parameter was releasing the connection to the db thus the query I was running by Invoke-Sqlcmd . When I set it to higher value it worked.