0

With a web search I found that sqlcmd is included in SQL Server.

Is there a command line client included in "SQL Server Management Studio 19"?

I wish to run some SQL scripts in an automated fashion.

I am not allowed to do a RDP Login on SQL Server 2022 (Provider managed).

UPDATE after answer:

Invoke-SQLcmd
Invoke-SQLcmd : The term 'Invoke-SQLcmd' is not recognized as the name of a cmdlet, function, script file, or operable
program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ Invoke-SQLcmd
+ ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Invoke-SQLcmd:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

and

Install-Module sqlserver
PackageManagement\Install-Package : No match was found for the specified search criteria and module name 'sqlserver'.
Try Get-PSRepository to see all available registered module repositories.
At C:\Program Files\WindowsPowerShell\Modules\PowershellGet\2.2.3\PSModule.psm1:9685 char:34
+ ... talledPackages = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Ex
   ception
    + FullyQu

1 Answer 1

2

You can use Powershell command Invoke-SQLcmd. Example:

Invoke-SQLcmd -ServerInstance Host\Instance -Database master -Query "select name from sys.databases where database_id<5"

If it's not present, open up PowerShell as an Administrator and install the sqlserver module by Install-Module sqlserver.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.