SQL Server: Use PowerShell Invoke-SQLCMD for T-SQL

In the previous articles, I have shared basic about the SQL Server PowerShell (sqlps) and how we can navigate SQL Server instance data using PowerShell.

SQL Server 2012: Working with the PowerShell Environment

In the SQLPS module, there are different commands available to extensively work with SQL Server.
The cmdlet command type contains most of the commands of SQLPS.

The Invoke-SQLCMD is also one command to execute T-SQL in PowerShell.
Here, I am sharing some of the examples of Invoke-SQLCMD to execute T-SQL in PowerShell.

First, list of all commands of SQLPS:

SQL Server PowerShell Get Modules

Check SQL Server Version:

SQL Server SELECT Version

Check Default database name:

SQL Server PowerShell Select DB Name

Execute SELECT statement:

SQL Server PowerShell Select Table

Execute SELECT with PowerShell Variable:

SQL Server PowerShell Variable

Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.

If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.

I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.

More from dbrnd.com

Leave a Reply

Be the First to Comment!

Notify of