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

Anvesh Patel

Leave a Reply

Be the First to Comment!

Notify of