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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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