<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Invoke-SQLCMD &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/invoke-sqlcmd/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Mon, 19 Sep 2016 19:48:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: Use PowerShell Invoke-SQLCMD for T-SQL</title>
		<link>https://www.dbrnd.com/2016/09/sql-server-use-powershell-invoke-sqlcmd-for-t-sql/</link>
					<comments>https://www.dbrnd.com/2016/09/sql-server-use-powershell-invoke-sqlcmd-for-t-sql/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sat, 17 Sep 2016 16:16:44 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[Invoke-SQLCMD]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tunning]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2554</guid>

					<description><![CDATA[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 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fsql-server-use-powershell-invoke-sqlcmd-for-t-sql%2F&amp;linkname=SQL%20Server%3A%20Use%20PowerShell%20Invoke-SQLCMD%20for%20T-SQL" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fsql-server-use-powershell-invoke-sqlcmd-for-t-sql%2F&amp;linkname=SQL%20Server%3A%20Use%20PowerShell%20Invoke-SQLCMD%20for%20T-SQL" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fsql-server-use-powershell-invoke-sqlcmd-for-t-sql%2F&amp;linkname=SQL%20Server%3A%20Use%20PowerShell%20Invoke-SQLCMD%20for%20T-SQL" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fsql-server-use-powershell-invoke-sqlcmd-for-t-sql%2F&amp;linkname=SQL%20Server%3A%20Use%20PowerShell%20Invoke-SQLCMD%20for%20T-SQL" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fsql-server-use-powershell-invoke-sqlcmd-for-t-sql%2F&amp;linkname=SQL%20Server%3A%20Use%20PowerShell%20Invoke-SQLCMD%20for%20T-SQL" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fsql-server-use-powershell-invoke-sqlcmd-for-t-sql%2F&amp;linkname=SQL%20Server%3A%20Use%20PowerShell%20Invoke-SQLCMD%20for%20T-SQL" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2016%2F09%2Fsql-server-use-powershell-invoke-sqlcmd-for-t-sql%2F&#038;title=SQL%20Server%3A%20Use%20PowerShell%20Invoke-SQLCMD%20for%20T-SQL" data-a2a-url="https://www.dbrnd.com/2016/09/sql-server-use-powershell-invoke-sqlcmd-for-t-sql/" data-a2a-title="SQL Server: Use PowerShell Invoke-SQLCMD for T-SQL"></a></p><p>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.</p>
<blockquote class="wp-embedded-content" data-secret="3npYm75DEm"><p><a href="https://www.dbrnd.com/2016/09/sql-server-2012-working-with-the-powershell-environment/">SQL Server 2012: Working with the PowerShell Environment</a></p></blockquote>
<p><iframe class="wp-embedded-content" sandbox="allow-scripts" security="restricted"  src="https://www.dbrnd.com/2016/09/sql-server-2012-working-with-the-powershell-environment/embed/#?secret=3npYm75DEm" data-secret="3npYm75DEm" width="600" height="338" title="&#8220;SQL Server 2012: Working with the PowerShell Environment&#8221; &#8212; Database Research &amp; Development" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe></p>
<p>In the SQLPS module, there are different commands available to extensively work with SQL Server.<br />
The cmdlet command type contains most of the commands of SQLPS.</p>
<blockquote><p>The Invoke-SQLCMD is also one command to execute T-SQL in PowerShell.<br />
Here, I am sharing some of the examples of Invoke-SQLCMD to execute T-SQL in PowerShell.</p></blockquote>
<p><strong>First, list of all commands of SQLPS:</strong></p><pre class="crayon-plain-tag">Get-command –module SQLPS</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellGetModules.png" rel="attachment wp-att-2559"><img fetchpriority="high" decoding="async" class="alignnone wp-image-2559 size-full" title="SQL Server PowerShell Get Modules" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellGetModules.png" alt="SQL Server PowerShell Get Modules" width="674" height="339" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellGetModules.png 674w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellGetModules-300x151.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellGetModules-150x75.png 150w" sizes="(max-width: 674px) 100vw, 674px" /></a></p>
<p><strong>Check SQL Server Version:</strong></p><pre class="crayon-plain-tag">Invoke-SQLCMD "select @@version;"</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerSELECTVersion.png" rel="attachment wp-att-2560"><img decoding="async" class="alignnone wp-image-2560 size-full" title="SQL Server SELECT Version" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerSELECTVersion.png" alt="SQL Server SELECT Version" width="672" height="180" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerSELECTVersion.png 672w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerSELECTVersion-300x80.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerSELECTVersion-150x40.png 150w" sizes="(max-width: 672px) 100vw, 672px" /></a></p>
<p><strong>Check Default database name: </strong></p><pre class="crayon-plain-tag">Invoke-SQLCMD "select db_name();"</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellSelectDBName.png" rel="attachment wp-att-2561"><img loading="lazy" decoding="async" class="alignnone wp-image-2561 size-full" title="SQL Server PowerShell Select DB Name" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellSelectDBName.png" alt="SQL Server PowerShell Select DB Name" width="672" height="161" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellSelectDBName.png 672w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellSelectDBName-300x72.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellSelectDBName-150x36.png 150w" sizes="auto, (max-width: 672px) 100vw, 672px" /></a></p>
<p><strong>Execute SELECT statement:</strong></p><pre class="crayon-plain-tag">Invoke-SQLCMD -Query "SELECT *FROM dbo.tbl_TestSnapshot;" –Database "dbrnd"</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellSelectTable.png" rel="attachment wp-att-2562"><img loading="lazy" decoding="async" class="alignnone wp-image-2562 size-full" title="SQL Server PowerShell Select Table" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellSelectTable.png" alt="SQL Server PowerShell Select Table" width="672" height="244" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellSelectTable.png 672w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellSelectTable-300x109.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellSelectTable-150x54.png 150w" sizes="auto, (max-width: 672px) 100vw, 672px" /></a></p>
<p><strong>Execute SELECT with PowerShell Variable: </strong></p><pre class="crayon-plain-tag">$MyVar = "Anvesh"
Invoke-SQLCMD -Query "SELECT *FROM dbo.tbl_TestSnapshot WHERE Name = '$($MyVar)';" –Database "dbrnd"</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellVariable.png" rel="attachment wp-att-2563"><img loading="lazy" decoding="async" class="alignnone wp-image-2563 size-full" title="SQL Server PowerShell Variable" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellVariable.png" alt="SQL Server PowerShell Variable" width="669" height="202" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellVariable.png 669w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellVariable-300x91.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellVariable-150x45.png 150w" sizes="auto, (max-width: 669px) 100vw, 669px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/09/sql-server-use-powershell-invoke-sqlcmd-for-t-sql/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
			</item>
	</channel>
</rss>
