Invoke-Sqlcmd vs sqlcmd utility

Invoke-Sqlcmd can run many of the scripts which can be run with the sqlcmd utility. However, Invoke-Sqlcmd runs in the PowerShell environment which is different than the command prompt environment sqlcmd runs in. Invoke-Sqlcmd has been modified to work in a PowerShell environment.

Not all the sqlcmd commands can be used in Invoke-Sqlcmd. Commands which are not available include the below:

  • :connect
  • :error
  • :out
  • :ed
  • :lis
  • :listva
  • :reset
  • :perftrace
  • :serverlist
The Invoke-Sqlcmd cmdlet does not initialize the sqlcmd environment or scripting variables such as SQLCMDDBNAME or SQLCMDWORKSTATION, nor does it  display messages, such as the output of PRINT statements, unless the PowerShell -Verbose common parameter is specified. For example:
Invoke-Sqlcmd -Query "PRINT N'abc';" -Verbose

Not all  the sqlcmd parameters are required  in the PowerShell environment. For example,  PowerShell formats all output from cmdlets, so  sqlcmd parameters specifying formatting options are not implemented in Invoke-Sqlcmd. 




Related Articles :

No comments yet... Be the first to leave a reply!

Software Reviews | Book Reviews | FAQs | Tips | Articles | Performance Tuning | Audit | BI | Clustering | Developer | Reporting | DBA | ASP.NET Ado | Views tips | | Developer FAQs | Replication Tips | OS Tips | Misc Tips | Index Tuning Tips | Hints Tips | High Availability Tips | Hardware Tips | ETL Tips | Components Tips | Configuration Tips | App Dev Tips | OLAP Tips | Admin Tips | Software Reviews | Error | Clustering FAQs | Performance Tuning FAQs | DBA FAQs |