Powershell - Invoke-sqlcmd to connect to a mssql server using different port



You might be able to use the following code to connect to an instance of sql server on a different port. Here 's how you can do it.


$containerServerInstancePort = "localhost,1400"
$sqlLoginName = "sa"
$sa_password = "mypassword"
$dbExist = Invoke-Sqlcmd -ServerInstance $containerServerInstancePort -Username $sqlLoginName
-Password $sa_password -Query "SELECT name FROM master.dbo.sysdatabases WHERE [name]='$dbName'"







Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20