Does Powershell Invoke-SqlCmd support ConnectionString in SQLPS

50 Views Asked by At

I have a PS script I wrote to insert/update a SQL DB. I create my connection string and then build some other parameters and then use Invoke-SqlCmd

$sqlConnString = "Server=$SQLServer; Database=$SQLDBName; User ID = $uid; Password = $sqlPwd; TrustServerCertificate=True;"

$sqlCmdParameters = @{
    InputFile = $callSqlScriptFile
    QueryTimeout = 1800
    ConnectionString = $sqlConnString
    Variable = $sqlCmdVariables
}
try {
    Invoke-SqlCmd @sqlCmdParameters
} catch {
    Write-Host -ForegroundColor Red "Encountered Error:"$_.Exception.Message
}

I have 3 servers that I’m testing this on. It works on server 1 and 2, but not on server 3. The error I get on Server 3 is: A parameter cannot be found that matches parameter name 'ConnectionString'.

All three servers are PowerShell v5.1.x Server 1 is Windows Server 2022, and servers 2 and 3 are Windows Server 2016.

When I run the following PS Command, I get this for each server:

Get-Module -ListAvailable -Name "*Sql*"

- Server 1: ModuleType > Manifest, Version > 15.0, Name > SQLPS
- Server 2: ModuleType > Script, Version > 22.2.0, Name > SqlServer
- Server 3: ModuleType > Script, Version > 22.2.0, Name > SqlServer 
    – and-- ModuleType > Manifest, Version > 1.0, Name > SQLPS

The only thing I can gather is that on server 1, SQLPS is at version 15.0 and I’m assuming ConnectionString is supported.

  • Server 2 is using SqlServer and I know ConnectionString is supported.
  • Server 3 is using both and I’m wondering if there is a conflict and it defaults SQLPS version 1.0 and ConnectionString is not supported.

However, if I run the following on server 3, it says Source = SqlServer

get-command Invoke-Sqlcmd

I cannot seem to figure out how to remove SQLPS from server 3, or update to version 15.0, or if this is even the issue.

0

There are 0 best solutions below