Difference Between Sqlcmd and Invoke-Sqlcmd

I am trying to learn Sqlcmd utility in PowerShell to run SQL queries, specifically for database administration.

Using Version 15.0.1300.359 NT

But I got confused, what is the difference between Sqlcmd and Invoke-Sqlcmd?

Why is it this command works:

Invoke-Sqlcmd -ServerInstance myinstance -Database AdventureWorks2017 "select top 3 * from [Person].[BusinessEntity]"

And this one does not work:

Invoke-Sqlcmd -S myinstance -d AdventureWorks2017 "select top 3 * from [Person].[BusinessEntity]"

By querying help I can clearly see that I should be able using all those variables:

1 Answer

If you're working on PowerShell scripting, I would recommend the use of the Module whenever possible. Invoke-SqlCmd will output objects, which are definitely easier to manipulate.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest