humzaqureshi
humzaqureshi

Reputation: 39

A parameter cannot be found that matches parameter name 'ConnectionString'

I am trying to connect to a database using a connection string and run a .sql script.

While trying to run:

Invoke-Sqlcmd -ConnectionString $CString -InputFile .\deleteOldData.sql

I got this error:

A parameter cannot be found that matches parameter name 'ConnectionString'

The Microsoft documentation has -ConnectionString listed as a part of Invoke-Sqlcmd so I'm confused why the command is not working.

Upvotes: 2

Views: 9769

Answers (1)

Morpheus
Morpheus

Reputation: 1634

The module SQLPS has an Invoke-Sqlcmd which does not have a -ConnectionString parameter. There is also an Invoke-Sqlcmd in the SqlServer module.

Install-Module -Name SqlServer

See this documention for more details.

SQLPS: The SQLPS module is included with the SQL Server installation (for backward compatibility), but is no longer being updated. The most up-to-date PowerShell module is the SqlServer module.

Upvotes: 4

Related Questions