<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://msmvps.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx</link><description>Installing SQL Server 2008 gives you SQLPS.exe, an application you can run which is a PowerShell including the PSDrives for SQL Server (and compatible with SQL Server 2005 as well!). But how do you make this work with your current copy of PowerShell?</description><dc:language>en</dc:language><generator>CommunityServer 2008.5 SP2 (Build: 40407.4157)</generator><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1677665</link><pubDate>Thu, 12 Mar 2009 01:34:34 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1677665</guid><dc:creator>Rob Farley</dc:creator><description>&lt;p&gt;Yes Mark, you&amp;#39;re correct. SQLPS isn&amp;#39;t without its uses, but all too often I want to hook into slightly more than what I have available.&lt;/p&gt;
&lt;p&gt;And I&amp;#39;m often running PowerShell anyway, which makes the snapins way more useful.&lt;/p&gt;
&lt;p&gt;Rob&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1677665" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1677632</link><pubDate>Wed, 11 Mar 2009 20:09:55 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1677632</guid><dc:creator>MarkTab</dc:creator><description>&lt;p&gt;By the way -- I will also provide a document quotation on why use SQLPS at all if anybody could simply add the PS PlugIn. &amp;nbsp;SQLPS is a &amp;quot;Power Shell Mini-Shell&amp;quot;:&lt;/p&gt;
&lt;p&gt;&amp;quot;By default, sqlps runs with the scripting execution policy set to Restricted, which prevents running any PowerShell scripts. You can use the Set-ExecutionPolicy cmdlet to enable running signed scripts, or any scripts. Only run scripts from trusted sources, and secure all input and output files using the appropriate NTFS permissions.&amp;quot;&lt;/p&gt;
&lt;p&gt;from &lt;a rel="nofollow" target="_new" href="http://msdn.microsoft.com/en-us/library/cc281962.aspx"&gt;msdn.microsoft.com/.../cc281962.aspx&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Powershell is, well, powerful, and a main concern for a SQL Server admin is inadvertently running something against a shared-database environment. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;SQLPS is therefore the default window when right-clicking an object in SSMS.&lt;/p&gt;
&lt;p&gt;The link I referenced provides a script for adding SQL Server snap-ins to any PowerShell environment (it is more than just three lines since it includes conditional registration, for example). &amp;nbsp;Also provided is a script to load SMO only (if, for example, the intention is to port to .NET and not use the SQL provider).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1677632" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1677626</link><pubDate>Wed, 11 Mar 2009 19:50:22 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1677626</guid><dc:creator>MarkTab</dc:creator><description>&lt;p&gt;Thanks for this post.&lt;/p&gt;
&lt;p&gt;For the TOTAL newbie, when I type:&lt;/p&gt;
&lt;p&gt;get-pssnapin -reg&lt;/p&gt;
&lt;p&gt;I receive:&lt;/p&gt;
&lt;p&gt;Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: SqlServerCmdletSnapin100&lt;/p&gt;
&lt;p&gt;PSVersion &amp;nbsp; : 1.0&lt;/p&gt;
&lt;p&gt;Description : This is a PowerShell snap-in that includes various SQL Server cmdlets.&lt;/p&gt;
&lt;p&gt;Name &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;: SqlServerProviderSnapin100&lt;/p&gt;
&lt;p&gt;PSVersion &amp;nbsp; : 1.0&lt;/p&gt;
&lt;p&gt;Description : SQL Server Provider&lt;/p&gt;
&lt;p&gt;Then, I should do (based on the &amp;quot;Name&amp;quot;):&lt;/p&gt;
&lt;p&gt;Add-PSSnapin SqlServerProviderSnapin100&lt;/p&gt;
&lt;p&gt;Add-PSSnapin SqlServerCmdletSnapin100&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1677626" width="1" height="1"&gt;</description></item><item><title>Learning PowerShell in SQL Server 2008 &amp;laquo; Home of the Scary DBA</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1651627</link><pubDate>Wed, 22 Oct 2008 15:29:05 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1651627</guid><dc:creator>Learning PowerShell in SQL Server 2008 « Home of the Scary DBA</dc:creator><description>&lt;p&gt;Pingback from &amp;nbsp;Learning PowerShell in SQL Server 2008 &amp;laquo; Home of the Scary DBA&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1651627" width="1" height="1"&gt;</description></item><item><title>PowerShell changes in SQL Server 2008 RC0</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1637163</link><pubDate>Tue, 24 Jun 2008 03:24:45 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1637163</guid><dc:creator>PowerShell changes in SQL Server 2008 RC0</dc:creator><description>&lt;p&gt;Pingback from &amp;nbsp;PowerShell changes in SQL Server 2008 RC0&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1637163" width="1" height="1"&gt;</description></item><item><title>PowerShell changes in SQL Server 2008 RC0</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1634250</link><pubDate>Thu, 12 Jun 2008 02:48:49 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1634250</guid><dc:creator>Rob Farley</dc:creator><description>&lt;p&gt;Regular readers of my blog will remember my post about how to get PowerShell for SQL into your regular&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1634250" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1607977</link><pubDate>Tue, 29 Apr 2008 01:57:09 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1607977</guid><dc:creator>Rob Farley</dc:creator><description>&lt;p&gt;Goodwin - there are some great books around. Pop down to a bookshop and glance through a few to find one that suits your learning style. But also read blogs like blogs.msdn.com/powershell to stay learning!&lt;/p&gt;
&lt;p&gt;Aaron - I'm not sure, because I don't run Exchange locally. However, if there's a PowerShell provider at all (through this Exchange Shell you mention), you should be able to see if it's treated as a snapin using &amp;quot;Get-PSSnapin -reg&amp;quot; like Darren and I did for the SQL stuff. And post back here to let me know how you go.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1607977" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1607967</link><pubDate>Tue, 29 Apr 2008 01:50:11 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1607967</guid><dc:creator>Aaron Guilmette</dc:creator><description>&lt;p&gt;Does anyone know if this works for the Exchange 2007 Command Shell? &amp;nbsp;For those of us that admin multiple platforms and applications, the prospect of PS bloat is demoralizing.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1607967" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1599077</link><pubDate>Tue, 22 Apr 2008 05:54:37 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1599077</guid><dc:creator>G D Milner</dc:creator><description>&lt;p&gt;In my opinion, the best book on Powershell is and remains Bruce Payette&amp;#39;s Powershell in Action. Also very good is the Windows PowerShell Cookbook by Lee Holmes. &lt;/p&gt;
&lt;p&gt;I just started reading Pro Windows PowerShell by Hristo Deshev, and that one looks pretty good, too. &lt;/p&gt;
&lt;p&gt;If you only buy one book, however, get Powershell in Action. &lt;/p&gt;
&lt;p&gt;Cheers&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1599077" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1591905</link><pubDate>Thu, 17 Apr 2008 09:33:26 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1591905</guid><dc:creator>Goodwin Robinson</dc:creator><description>&lt;p&gt;Hi Rob and everyone!&lt;/p&gt;
&lt;p&gt;Great article, I DBA managing just over 60 SQL Server 2000/2005 Instances, supporting over 300 databses and it seems my day will be much more productive if I can script in PowerShell.&lt;/p&gt;
&lt;p&gt;I know the basis in VBScript via WSH, so some knowledge base on my part to work with, but will like to take on PowerShell.&lt;/p&gt;
&lt;p&gt;So, Please where would you suggest I start - books and web resource etc I could use to get up to speed.&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Goodwin&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1591905" width="1" height="1"&gt;</description></item><item><title>PowerShell - Where is It?</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1590682</link><pubDate>Wed, 16 Apr 2008 15:39:25 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1590682</guid><dc:creator>Carpe Datum</dc:creator><description>&lt;p&gt;As you may know, we’ve created a SQL Server 2008 provider for PowerShell. With this very cool feature&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1590682" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1553151</link><pubDate>Tue, 25 Mar 2008 21:16:01 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1553151</guid><dc:creator>Rob Farley</dc:creator><description>&lt;p&gt;Sorry Steve, I actually haven't tried this! I doubt it'll work, but please try and let me know!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1553151" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1552824</link><pubDate>Tue, 25 Mar 2008 12:02:50 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1552824</guid><dc:creator>steve</dc:creator><description>&lt;p&gt;So do you need to install SQL 2008 or can you just copy the SQLPS.exe to your local machine?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1552824" width="1" height="1"&gt;</description></item><item><title>MSDN Blog Postings  &amp;raquo; SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1548963</link><pubDate>Thu, 20 Mar 2008 22:44:26 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1548963</guid><dc:creator>MSDN Blog Postings  » SQL Server 2008 PowerShell SnapIn</dc:creator><description>&lt;p&gt;Pingback from &amp;nbsp;MSDN Blog Postings &amp;nbsp;&amp;amp;raquo; SQL Server 2008 PowerShell SnapIn&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1548963" width="1" height="1"&gt;</description></item><item><title>SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1548863</link><pubDate>Thu, 20 Mar 2008 21:11:05 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1548863</guid><dc:creator>Contagious Curiosity</dc:creator><description>&lt;p&gt;Oh, the things you find when you are writing a book. Now, the problem is to spend less time &amp;#39;finding&amp;#39;&lt;/p&gt;
&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1548863" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1543181</link><pubDate>Fri, 14 Mar 2008 20:59:45 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1543181</guid><dc:creator>Rob Farley</dc:creator><description>&lt;p&gt;But 'Invoke-SqlCmd' comes with the SQL PS Provider, so you don't need to roll your own.&lt;/p&gt;
&lt;p&gt;And for backup times, you don't need to go back into T-SQL, you can just do it from SMO directly:&lt;/p&gt;
&lt;p&gt;PS SQL:\rob-pc\default\Databases&amp;gt; gci | select-object name,lastbackupdate&lt;/p&gt;
&lt;p&gt;And if you need to make SMO connections, you can. I guess it's no different really to using invoke-sqlcmd.&lt;/p&gt;
&lt;p&gt;Of course, with SSMS 2008, you can do Local Server Group queries, which makes this much easier to do using T-SQL directly.&lt;/p&gt;
&lt;p&gt;Rob&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1543181" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1542925</link><pubDate>Fri, 14 Mar 2008 15:03:48 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1542925</guid><dc:creator>SQL_Guru</dc:creator><description>&lt;p&gt;Thanks for figuring out the PSSnapins for SQL 2008. &amp;nbsp;I wasn&amp;#39;t looking forward to having 2 different flavors of Powershell open all the time. &amp;nbsp;This makes it easier to integrate with my existing tools.&lt;/p&gt;
&lt;p&gt;In terms of administrating SQL using PS. &amp;nbsp;It is almost a must for a large environment. &amp;nbsp;Just try to use SSMS to figure out when the last backups happened to all databases on all servers. &amp;nbsp;It works ok on 1 server, but as the number goes up, so does the amount of time it takes. &amp;nbsp;With a script/CmdLet you can do things like the following:&lt;/p&gt;
&lt;p&gt;gc .\SQLServers.txt | % { Invoke-SQL.ps1 -Server $_ -InputFileQuery .\BackupStatus.sql }&lt;/p&gt;
&lt;p&gt;Now you have a list of all backups on all servers and can go from there (After you&amp;#39;ve made the BackupStatus.sql script). &amp;nbsp;This also makes a huge difference if you have a lot of databases. &amp;nbsp;For example at last count I was checking the backup status of over 1100 databases using PowerShell. &amp;nbsp;Try that with SSMS. &amp;nbsp;You can do it, but it takes DAYS. &amp;nbsp;Currently it takes me about 3 minutes to run the script and a few more minutes to review the results. &amp;nbsp;Now you could do this with other scripting languages, but it isn&amp;#39;t as easy to get access to the underlying objects/rows/columns from the command line. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Other Possible Uses:&lt;/p&gt;
&lt;p&gt;Invoke-SQL -S Dev1 -Q &amp;quot;select @@servername as &amp;#39;Server&amp;#39;, getdate() as &amp;#39;ServerTime&amp;#39;&amp;quot; # Check time on server&lt;/p&gt;
&lt;p&gt;Invoke-SQL -S Dev1 -Q &amp;quot;exec sp_who2&amp;quot; &amp;nbsp;# what&amp;#39;s running on a server&lt;/p&gt;
&lt;p&gt;Invoke-SQL -S Dev1 -Q &amp;quot;exec sp_helpdb&amp;quot; # Get Name and Size of databases&lt;/p&gt;
&lt;p&gt;# Get number of blocked processes for one server or for all servers.&lt;/p&gt;
&lt;p&gt;Invoke-SQL -S Dev1 -Query &amp;quot;select @@servername as &amp;#39;Server&amp;#39;, count(*) as &amp;#39;Blocked&amp;#39; from master.dbo.sysprocesses where blocked &amp;lt;&amp;gt; 0&amp;quot; &lt;/p&gt;
&lt;p&gt;gc .\SQLServers.txt | % { Invoke-SQL -Server $_ -Query &amp;quot;select @@servername as &amp;#39;Server&amp;#39;, count(*) as &amp;#39;Blocked&amp;#39; from master.dbo.sysprocesses where blocked &amp;lt;&amp;gt; 0&amp;quot; }&lt;/p&gt;
&lt;p&gt;#Insert data using a hashtable as the source for parameters. &amp;nbsp;My Invoke-SQL.ps1 script adds parameters based on the hashtable passed in.&lt;/p&gt;
&lt;p&gt;Invoke-Sql -S Dev1 -Database Test1 -Query &amp;quot;insert ServerList (ServerName, IPAddress) values (@ServerName, @IPAddress)&amp;quot; -Parameters @{&amp;#39;@ServerName&amp;#39;=&amp;#39;ProdWeb01&amp;#39;;&amp;#39;@IPAddress&amp;#39;=&amp;#39;192.168.0.134&amp;#39;}&lt;/p&gt;
&lt;p&gt;These are a few of the things I use almost every day, although my scripts are more complex. &amp;nbsp;Hopefully it will give you an idea of what you can do with powershell and why it&amp;#39;s usefull for administrating SQL Servers.&lt;/p&gt;
&lt;p&gt;p.s. The Invoke-SQL.ps1 script in the examples isn&amp;#39;t available online yet. &amp;nbsp;It&amp;#39;s something I cooked up myself.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1542925" width="1" height="1"&gt;</description></item><item><title>re: SQL Server 2008 PowerShell SnapIn</title><link>http://msmvps.com/blogs/robfarley/archive/2008/03/04/sql-server-2008-powershell-snapin.aspx#1534470</link><pubDate>Wed, 05 Mar 2008 20:38:24 GMT</pubDate><guid isPermaLink="false">d67277c4-116b-43f1-b688-e9ef184ea916:1534470</guid><dc:creator>NicoAtMicrosoft</dc:creator><description>&lt;p&gt;I hear PowerShell is an improvement over VBScript, but I&amp;#39;m impartial either way. &amp;nbsp;I wonder if there will be any improvements on this in the RTM of SQL Server 2008?&lt;/p&gt;
&lt;p&gt;**************&lt;/p&gt;
&lt;p&gt;Nico del Castillo&lt;/p&gt;
&lt;p&gt;Microsoft 2008 Joint Launch Team&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.microsoft.com/2008jointlaunch"&gt;www.microsoft.com/2008jointlaunch&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://msmvps.com/aggbug.aspx?PostID=1534470" width="1" height="1"&gt;</description></item></channel></rss>