<?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>PowerShell &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/powershell/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: PowerShell Function to find System Admin Roles</title>
		<link>https://www.dbrnd.com/2016/09/sql-server-powershell-function-to-find-system-admin-roles/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Mon, 19 Sep 2016 16:16:21 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[SMO]]></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[System Admin Role]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=2575</guid>

					<description><![CDATA[In this post, I am sharing one PowerShell function to find all system admin roles of the SQL Server. This function helps to those DBAs who are working with PowerShell. Using this function DBAs can easily list out all System Admin roles of a particular database. Below is a script to create a function: The [&#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-powershell-function-to-find-system-admin-roles%2F&amp;linkname=SQL%20Server%3A%20PowerShell%20Function%20to%20find%20System%20Admin%20Roles" 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-powershell-function-to-find-system-admin-roles%2F&amp;linkname=SQL%20Server%3A%20PowerShell%20Function%20to%20find%20System%20Admin%20Roles" 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-powershell-function-to-find-system-admin-roles%2F&amp;linkname=SQL%20Server%3A%20PowerShell%20Function%20to%20find%20System%20Admin%20Roles" 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-powershell-function-to-find-system-admin-roles%2F&amp;linkname=SQL%20Server%3A%20PowerShell%20Function%20to%20find%20System%20Admin%20Roles" 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-powershell-function-to-find-system-admin-roles%2F&amp;linkname=SQL%20Server%3A%20PowerShell%20Function%20to%20find%20System%20Admin%20Roles" 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-powershell-function-to-find-system-admin-roles%2F&amp;linkname=SQL%20Server%3A%20PowerShell%20Function%20to%20find%20System%20Admin%20Roles" 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-powershell-function-to-find-system-admin-roles%2F&#038;title=SQL%20Server%3A%20PowerShell%20Function%20to%20find%20System%20Admin%20Roles" data-a2a-url="https://www.dbrnd.com/2016/09/sql-server-powershell-function-to-find-system-admin-roles/" data-a2a-title="SQL Server: PowerShell Function to find System Admin Roles"></a></p><p>In this post, I am sharing one PowerShell function to find all system admin roles of the SQL Server.</p>
<p>This function helps to those DBAs who are working with PowerShell. Using this function DBAs can easily list out all System Admin roles of a particular database.</p>
<p><strong>Below is a script to create a function:</strong><br />
The DBA has to pass server name as input parameter.</p><pre class="crayon-plain-tag">function Find_SystemAdmin_Role ($servername)
{
   $ServerVar="$servername"
   $ServerVar=New-Object "Microsoft.SqlServer.Management.Smo.Server" "$ServerVar"
   $ServerRole = $ServerVar.Roles | where {$_.Name -eq 'sysadmin'}
   $ServerVar
   $ServerRole.EnumServerRoleMembers()
}</pre><p>
<strong>Script to call this function:</strong></p><pre class="crayon-plain-tag">Find_SystemAdmin_Role "ServerName_DBRND"</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellFunctionSystemAdmin.png" rel="attachment wp-att-2578"><img fetchpriority="high" decoding="async" class="alignnone wp-image-2578 size-full" title="SQL Server PowerShell Function System Admin" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellFunctionSystemAdmin.png" alt="SQL Server PowerShell Function System Admin" width="670" height="337" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellFunctionSystemAdmin.png 670w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellFunctionSystemAdmin-300x151.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellFunctionSystemAdmin-150x75.png 150w" sizes="(max-width: 670px) 100vw, 670px" /></a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2012: All Database and Log backups using PowerShell</title>
		<link>https://www.dbrnd.com/2016/09/sql-server-2012-all-database-and-log-backups-using-powershell/</link>
					<comments>https://www.dbrnd.com/2016/09/sql-server-2012-all-database-and-log-backups-using-powershell/#comments</comments>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Sun, 18 Sep 2016 16:16:51 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[SQL Server DBA Script]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[Backup-SqlDatabase]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></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=2566</guid>

					<description><![CDATA[In this post, I am going share scripts to take all database and log backups using SQL Server PowerShell. Using T-SQL, we can also take all databases backup using one single script, but some of the Database Administrators like to perform this kind of task using PowerShell because sometimes it is much faster and it [&#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-2012-all-database-and-log-backups-using-powershell%2F&amp;linkname=SQL%20Server%202012%3A%20All%20Database%20and%20Log%20backups%20using%20PowerShell" 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-2012-all-database-and-log-backups-using-powershell%2F&amp;linkname=SQL%20Server%202012%3A%20All%20Database%20and%20Log%20backups%20using%20PowerShell" 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-2012-all-database-and-log-backups-using-powershell%2F&amp;linkname=SQL%20Server%202012%3A%20All%20Database%20and%20Log%20backups%20using%20PowerShell" 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-2012-all-database-and-log-backups-using-powershell%2F&amp;linkname=SQL%20Server%202012%3A%20All%20Database%20and%20Log%20backups%20using%20PowerShell" 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-2012-all-database-and-log-backups-using-powershell%2F&amp;linkname=SQL%20Server%202012%3A%20All%20Database%20and%20Log%20backups%20using%20PowerShell" 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-2012-all-database-and-log-backups-using-powershell%2F&amp;linkname=SQL%20Server%202012%3A%20All%20Database%20and%20Log%20backups%20using%20PowerShell" 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-2012-all-database-and-log-backups-using-powershell%2F&#038;title=SQL%20Server%202012%3A%20All%20Database%20and%20Log%20backups%20using%20PowerShell" data-a2a-url="https://www.dbrnd.com/2016/09/sql-server-2012-all-database-and-log-backups-using-powershell/" data-a2a-title="SQL Server 2012: All Database and Log backups using PowerShell"></a></p><p>In this post, I am going share scripts to take all database and log backups using SQL Server PowerShell.</p>
<p>Using T-SQL, we can also take all databases backup using one single script, but some of the Database Administrators like to perform this kind of task using PowerShell because sometimes it is much faster and it is executing from outside of the SQL Server.</p>
<blockquote><p>SQL Server 2012 cmdlet introduced a new command to take database backups and the command name is &#8220;Backup-SqlDatabase&#8221;.</p></blockquote>
<p><strong>Execute below command in PowerShell to get the help of &#8220;Backup-SqlDatabase&#8221;:</strong></p><pre class="crayon-plain-tag">help Backup-SqlDatabase -full</pre><p>
<strong>PowerShell script to take all database backups:</strong><br />
Generating file name with the date.</p><pre class="crayon-plain-tag">$BackupDate = Get-Date -Format MMddyy
foreach($database in (Get-ChildItem)) { 
$dbName = $database.Name
$bakFilePath = "C:\temp\" + $dbName + "_" + $BackupDate + ".bak"
Backup-SqlDatabase -Database $dbName -BackupFile $bakFilePath -Initialize }</pre><p>
<strong>PowerShell script to take all database log backups:</strong><br />
Generating file name with the date.</p><pre class="crayon-plain-tag">$BackupDate = Get-Date -Format MMddyy_hhmm
foreach($database in (Get-ChildItem)) {
$dbName = $database.Name
$trnFilePath = "C:\temp\" + $dbName + "_" + $BackupDate + ".trn"
Backup-SqlDatabase -Database $dbName -BackupAction Log -BackupFile $trnFilePath -Initialize}</pre><p>
<a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDatabaseBackup.png" rel="attachment wp-att-2573"><img decoding="async" class="alignnone wp-image-2573 size-full" title="SQL Server PowerShell Database Backup" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDatabaseBackup.png" alt="SQL Server PowerShell Database Backup" width="667" height="205" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDatabaseBackup.png 667w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDatabaseBackup-300x92.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDatabaseBackup-150x46.png 150w" sizes="(max-width: 667px) 100vw, 667px" /></a></p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.dbrnd.com/2016/09/sql-server-2012-all-database-and-log-backups-using-powershell/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
			</item>
		<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 loading="lazy" 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="auto, (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 loading="lazy" 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="auto, (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>
		<item>
		<title>SQL Server: The sqlps PowerShell for easy Database File Navigation</title>
		<link>https://www.dbrnd.com/2016/09/sql-server-the-sqlps-powershell-for-easy-database-file-navigation/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Fri, 16 Sep 2016 16:16:33 +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[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=2539</guid>

					<description><![CDATA[In the previous article, I have shared basic detail about the working with the Windows PowerShell for the SQL Server. SQL Server 2012: Working with the PowerShell Environment Using sqlps PowerShell provider, you can easily navigate all files of SQL Server Instance like any other file system. When Database Administrator requires to navigate or search [&#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-the-sqlps-powershell-for-easy-database-file-navigation%2F&amp;linkname=SQL%20Server%3A%20The%20sqlps%20PowerShell%20for%20easy%20Database%20File%20Navigation" 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-the-sqlps-powershell-for-easy-database-file-navigation%2F&amp;linkname=SQL%20Server%3A%20The%20sqlps%20PowerShell%20for%20easy%20Database%20File%20Navigation" 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-the-sqlps-powershell-for-easy-database-file-navigation%2F&amp;linkname=SQL%20Server%3A%20The%20sqlps%20PowerShell%20for%20easy%20Database%20File%20Navigation" 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-the-sqlps-powershell-for-easy-database-file-navigation%2F&amp;linkname=SQL%20Server%3A%20The%20sqlps%20PowerShell%20for%20easy%20Database%20File%20Navigation" 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-the-sqlps-powershell-for-easy-database-file-navigation%2F&amp;linkname=SQL%20Server%3A%20The%20sqlps%20PowerShell%20for%20easy%20Database%20File%20Navigation" 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-the-sqlps-powershell-for-easy-database-file-navigation%2F&amp;linkname=SQL%20Server%3A%20The%20sqlps%20PowerShell%20for%20easy%20Database%20File%20Navigation" 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-the-sqlps-powershell-for-easy-database-file-navigation%2F&#038;title=SQL%20Server%3A%20The%20sqlps%20PowerShell%20for%20easy%20Database%20File%20Navigation" data-a2a-url="https://www.dbrnd.com/2016/09/sql-server-the-sqlps-powershell-for-easy-database-file-navigation/" data-a2a-title="SQL Server: The sqlps PowerShell for easy Database File Navigation"></a></p><p>In the previous article, I have shared basic detail about the working with the Windows PowerShell for the SQL Server.</p>
<blockquote class="wp-embedded-content" data-secret="YfAtLBZxTw"><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 loading="lazy" 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=YfAtLBZxTw" data-secret="YfAtLBZxTw" 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>Using sqlps PowerShell provider, you can easily navigate all files of SQL Server Instance like any other file system.</p>
<blockquote><p>When Database Administrator requires to navigate or search different objects of a Database, PowerShell is much faster than T-SQL.<br />
At single window DBA can navigate all different objects and file of a Database Server and it saves the time of Database Administrator to write a multiple T-SQL for accessing database instance information.</p></blockquote>
<p><strong>First start, PowerShell by right clicking on database in SSMS.</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShell-1.png" rel="attachment wp-att-2545"><img loading="lazy" decoding="async" class="alignnone wp-image-2545 size-full" title="SQL Server PowerShell" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShell-1.png" alt="SQL Server PowerShell" width="341" height="379" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShell-1.png 341w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShell-1-270x300.png 270w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShell-1-150x167.png 150w" sizes="auto, (max-width: 341px) 100vw, 341px" /></a></p>
<p><strong>In that root path, you can execute [dir] command to get a list of all SQL Server Folders.</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDir.png" rel="attachment wp-att-2546"><img loading="lazy" decoding="async" class="alignnone wp-image-2546 size-full" title="SQL Server PowerShell Dir" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDir.png" alt="SQL Server PowerShell Dir" width="673" height="297" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDir.png 673w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDir-300x132.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDir-150x66.png 150w" sizes="auto, (max-width: 673px) 100vw, 673px" /></a></p>
<p><strong>Using [cd], you can select any folder like below, I have selected Databases folder.</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellCD.png" rel="attachment wp-att-2547"><img loading="lazy" decoding="async" class="alignnone wp-image-2547 size-full" title="SQL Server PowerShell CD" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellCD.png" alt="SQL Server PowerShell CD" width="677" height="127" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellCD.png 677w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellCD-300x56.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellCD-150x28.png 150w" sizes="auto, (max-width: 677px) 100vw, 677px" /></a></p>
<p><strong>Execute [dir] for Databases.</strong></p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDBDir.png" rel="attachment wp-att-2548"><img loading="lazy" decoding="async" class="alignnone wp-image-2548 size-full" title="SQL Server PowerShell DB Dir" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDBDir.png" alt="SQL Server PowerShell DB Dir" width="678" height="206" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDBDir.png 678w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDBDir-300x91.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellDBDir-150x46.png 150w" sizes="auto, (max-width: 678px) 100vw, 678px" /></a></p>
<p><strong>Using [cd..], you can go back to a particular folder and can select a new folder.</strong><br />
In below example, I have selected Logins folder.<br />
You can easily get all the available Logins by execution [dir] on that folder.</p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellChangeCD.png" rel="attachment wp-att-2549"><img loading="lazy" decoding="async" class="alignnone wp-image-2549 size-full" title="SQL Server PowerShell Change CD" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellChangeCD.png" alt="SQL Server PowerShell Change CD" width="675" height="267" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellChangeCD.png 675w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellChangeCD-300x119.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellChangeCD-150x59.png 150w" sizes="auto, (max-width: 675px) 100vw, 675px" /></a></p>
<p><strong>Another example is to list out all tables of a particular database.</strong><br />
select Databases -&gt; Database -&gt; Tables.</p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellTablesDir.png" rel="attachment wp-att-2551"><img loading="lazy" decoding="async" class="alignnone wp-image-2551 size-full" title="SQL Server PowerShell Tables Dir" src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellTablesDir.png" alt="SQL Server PowerShell Tables Dir" width="676" height="340" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellTablesDir.png 676w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellTablesDir-300x151.png 300w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShellTablesDir-150x75.png 150w" sizes="auto, (max-width: 676px) 100vw, 676px" /></a></p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2012: Working with the PowerShell Environment</title>
		<link>https://www.dbrnd.com/2016/09/sql-server-2012-working-with-the-powershell-environment/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 15 Sep 2016 17:55:24 +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[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=2531</guid>

					<description><![CDATA[The initially PowerShell integrated with SQL Server 2008 as mini-shell with limited options. Now the Microsoft launched fully functional PowerShell with SQL Server 2012. The PowerShell is a powerful scripting shell for administrators and developers to automate different tasks of the SQL Server. PowerShell is becoming more central to the Windows management model and can [&#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-2012-working-with-the-powershell-environment%2F&amp;linkname=SQL%20Server%202012%3A%20Working%20with%20the%20PowerShell%20Environment" 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-2012-working-with-the-powershell-environment%2F&amp;linkname=SQL%20Server%202012%3A%20Working%20with%20the%20PowerShell%20Environment" 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-2012-working-with-the-powershell-environment%2F&amp;linkname=SQL%20Server%202012%3A%20Working%20with%20the%20PowerShell%20Environment" 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-2012-working-with-the-powershell-environment%2F&amp;linkname=SQL%20Server%202012%3A%20Working%20with%20the%20PowerShell%20Environment" 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-2012-working-with-the-powershell-environment%2F&amp;linkname=SQL%20Server%202012%3A%20Working%20with%20the%20PowerShell%20Environment" 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-2012-working-with-the-powershell-environment%2F&amp;linkname=SQL%20Server%202012%3A%20Working%20with%20the%20PowerShell%20Environment" 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-2012-working-with-the-powershell-environment%2F&#038;title=SQL%20Server%202012%3A%20Working%20with%20the%20PowerShell%20Environment" data-a2a-url="https://www.dbrnd.com/2016/09/sql-server-2012-working-with-the-powershell-environment/" data-a2a-title="SQL Server 2012: Working with the PowerShell Environment"></a></p><p><em>The initially PowerShell integrated with SQL Server 2008 as mini-shell with limited options.<br />
Now the Microsoft launched fully functional PowerShell with SQL Server 2012.</em></p>
<blockquote><p>The PowerShell is a powerful scripting shell for administrators and developers to automate different tasks of the SQL Server.</p></blockquote>
<blockquote><p>PowerShell is becoming more central to the Windows management model and can provide a common framework for managing all the different servers in a Microsoft Windows infrastructure.<br />
PowerShell can manage Windows, SQL Server, SharePoint and others.</p></blockquote>
<blockquote><p>PowerShell is one of the good alternatives to manage SQL Server and it is one kind of bridge between SQL Server and Operating System(OS) to accessing and managing system and network resources.<br />
Unlike T-SQL, PowerShell can access resources that are outside of SQL Server.<br />
PowerShell is also capable to use advanced .NET functions which are not available in T-SQL.</p></blockquote>
<blockquote><p>PowerShell can also run T-SQL queries using Invoke-Sqlcmd.<br />
But the syntax and script coding of the PowerShell is very difficult to learn for non-developers.</p></blockquote>
<blockquote><p><strong>The sqlps is an additional module</strong> to configure Windows PowerShell for the SQL Server.<br />
It supports different types of cmdlets including like: Invoke-Sqlcmd, Add-SqlAvailabilitiyDatabase, Join-SqlAvailabilityGroup, Backup-SqlDatabase, Restore-SqlDatabase.</p></blockquote>
<p><strong>How to open PowerShell from the SSMS?<br />
</strong><br />
You can directly open windows PowerShell from the SSMS.<br />
You can right click on any object and open the PowerShell window and it opens directly under the Windows SQL Server disk location.</p>
<p><a href="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShell.png" rel="attachment wp-att-2535"><img loading="lazy" decoding="async" class="alignnone wp-image-2535 size-full" title="SQL Server PowerShell " src="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShell.png" alt="SQL Server PowerShell " width="341" height="379" srcset="https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShell.png 341w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShell-270x300.png 270w, https://www.dbrnd.com/wp-content/uploads/2016/04/SQLServerPowerShell-150x167.png 150w" sizes="auto, (max-width: 341px) 100vw, 341px" /></a></p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
