<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www.sqlservercentral.com/blogs/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>Chad Miller</title><link>http://www.sqlservercentral.com/blogs/chadmiller/default.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007.1 (Build: 20917.1142)</generator><item><title>SQLIse A Powershell Based SQL Server Query Tool</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/03/10/sqlise-a-powershell-based-sql-server-query-tool.aspx</link><pubDate>Wed, 10 Mar 2010 10:31:00 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:18521</guid><dc:creator>cmille19</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=18521</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/03/10/sqlise-a-powershell-based-sql-server-query-tool.aspx#comments</comments><description>&lt;p&gt;&lt;a href="http://sqlpsx.codeplex.com/" target="_blank"&gt;SQL Server Powershell Powershell Extensions&lt;/a&gt; (SQLPSX) has been updated to version 2.1. The most notable change is the addition of a Powershell Integrated Scripting Editor (ISE) module called SQLIse (pronounced “SQL Ice”). The module provides a basic IDE for T-SQL that includes the ability to edit, execute, parse and format SQL code from within Powershell ISE.&lt;/p&gt; &lt;h3&gt;SQLIse Features&lt;/h3&gt; &lt;ul&gt; &lt;li&gt;Offline parsing of T-SQL code&lt;/li&gt; &lt;li&gt;Formatting (prettifying) of T-SQL with an extensive customization abilities&lt;/li&gt; &lt;li&gt;Comment/Uncomment T-SQL code&lt;/li&gt; &lt;li&gt;Uppercase/Lowercase T-SQL code&lt;/li&gt; &lt;li&gt;Execute T-SQL code and output to grid, text, text file or CSV file&lt;/li&gt; &lt;li&gt;Apply any of the above actions to selections of code by highlighting&lt;/li&gt;&lt;/ul&gt; &lt;h3&gt;SQLIse Requirements&lt;/h3&gt; &lt;p&gt;SQLIse uses the following modules that part of the &lt;a href="http://www.codeplex.com/" target="_blank"&gt;CodePlex&lt;/a&gt; project &lt;a href="http://sqlpsx.codeplex.com/" target="_blank"&gt;SQLPSX&lt;/a&gt; as well as &lt;a href="http://code.msdn.microsoft.com/PowerShellPack" target="_blank"&gt;PowershellPack&lt;/a&gt; available on &lt;a href="http://code.msdn.microsoft.com/" target="_blank"&gt;MSDN Code Gallery&lt;/a&gt;:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;SQLParser (SQLPSX)&lt;/li&gt; &lt;li&gt;AdoLib (SQLPSX)&lt;/li&gt; &lt;li&gt;IsePack (PowershellPack)&lt;/li&gt; &lt;li&gt;WPK (PowershellPack)&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;&lt;em&gt;NOTE: The use of external modules is a change for SQLPSX, however sometimes its important to leverage other people’s code to greatly simplify your own. So, in order to use SQLIse you’ll need to install both SQLPSX and the PowershellPack.&lt;/em&gt; &lt;/p&gt; &lt;h3&gt;Credits&lt;/h3&gt; &lt;p&gt;A big thanks to &lt;a href="http://powershellstation.com/" target="_blank"&gt;Mike Shepard&lt;/a&gt; for creating the AdoLib module and James Brundage for his excellent WPK and IsePack modules that make creating GUIs and customizing Powershell ISE seem easy.&lt;/p&gt; &lt;h3&gt;Next Steps&lt;/h3&gt; &lt;p&gt;Check out this &lt;a href="http://www.youtube.com/watch?v=1KcNSHn7oTA" target="_blank"&gt;5 minute video of SQLIse&lt;/a&gt;: and leave some &lt;a href="http://sqlpsx.codeplex.com/Thread/View.aspx?ThreadId=204395" target="_blank"&gt;feedback on the SQLPSX site&lt;/a&gt;:&lt;/p&gt; &lt;div style="padding-bottom:0px;margin:0px;padding-left:0px;padding-right:0px;display:inline;float:none;padding-top:0px;"&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;  &lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=18521" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>Querying Oracle from Powershell Part 2</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/03/01/querying-oracle-from-powershell-part-2.aspx</link><pubDate>Mon, 01 Mar 2010 10:04:51 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:18253</guid><dc:creator>cmille19</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=18253</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/03/01/querying-oracle-from-powershell-part-2.aspx#comments</comments><description>&lt;p&gt;In &lt;a href="http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!925.entry" target="_blank"&gt;part one&lt;/a&gt; we installed and configured the Oracle client software, in this post we will query an Oracle database from Powershell.  In addition we’ll look at one way to handle storing sensitive password information.&lt;/p&gt;
&lt;h3&gt;Querying and Oracle Database&lt;/h3&gt;
&lt;p&gt;To query an Oracle database we’ll use a function called &lt;a href="http://poshcode.org/1591" target="_blank"&gt;Get-OLEDBData&lt;/a&gt;. The code listed below and is also available on &lt;a href="http://poshcode.org/" target="_blank"&gt;PoshCode&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#00008b;"&gt;function&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Get-OLEDBData&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$connectstring&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$sql&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;            
   &lt;span style="color:#ff4500;"&gt;$OLEDBConn&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;New-Object&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;System.Data.OleDb.OleDbConnection&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$connectstring&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
   &lt;span style="color:#ff4500;"&gt;$OLEDBConn&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;open&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
   &lt;span style="color:#ff4500;"&gt;$readcmd&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;New-Object&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;system.Data.OleDb.OleDbCommand&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$sql&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$OLEDBConn&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
   &lt;span style="color:#ff4500;"&gt;$readcmd&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;CommandTimeout&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;300&amp;#39;&lt;/span&gt;            
   &lt;span style="color:#ff4500;"&gt;$da&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;New-Object&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;system.Data.OleDb.OleDbDataAdapter&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$readcmd&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
   &lt;span style="color:#ff4500;"&gt;$dt&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;New-Object&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;system.Data.datatable&lt;/span&gt;            
   &lt;span style="color:#008080;"&gt;[void]&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$da&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;fill&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$dt&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
   &lt;span style="color:#ff4500;"&gt;$OLEDBConn&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;close&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
   &lt;span style="color:#00008b;"&gt;return&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$dt&lt;/span&gt;            
&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The Get-OLEDBData function has been tested against SQL Server, Informix, Oracle and Excel data sources. In addition other data source can be addressed all that is needed is a valid connection string, the ability the data source to support OLEDB connections and of course the appropriate drivers. See &lt;a href="http://connectionstrings.com/" target="_blank"&gt;connectionstring.com&lt;/a&gt; for a list of connection string examples. The hard part of querying an Oracle database from Powershell is setting up the Oracle Client software demonstrated in part one. Using the Get-OLEDBData function is simple, just pass a connection string and a query as follows:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#ff4500;"&gt;$connString&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;password=assword;User ID=SYSTEM;Data Source=XE;Provider=OraOLEDB.Oracle&amp;quot;&lt;/span&gt;            
&lt;span style="color:#ff4500;"&gt;$qry&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;SELECT * FROM HR.DEPARTMENTS&amp;quot;&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;./Get-OLEDBData&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$connString&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$qry&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;This will return all rows from the DEPARTMENTS table in HR schema:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1m_rWyWHULjmPsExqx09fSewEinKUhE3RpwAqw3cz3zbmHSIr1hI6_CUFNrsgNMAhlBKhMG9Ho4QO4OT-OF3JSZH6owFXjJ6nyXYdfT-Hcw4dzR18PHbimO7gthO3RIH1yegdVWqtHZ1cYlhkhpVGIpg/oraclePowershell12.jpg" rel="WLPP"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="oraclePowershell1" border="0" alt="oraclePowershell1" src="https://j2ttpq.blu.livefilestore.com/y1meD9_4s-ZQ0RygrE4zxOiMjuJjERX0xtY9KkPdLAHt5BSpLeh4061Q0v1xD1O_TLz0BkNm52dOZlRrbrHYIrxGPGNLbpQWckTA-7Eo1kGUQocgQ6UCR2bYVoWvrJhAFzElZM_0dRIP0oqHHR3-jOGmw/oraclePowershell1_thumb.jpg" width="244" height="158" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;As long as your Oracle client software is installed and configured correctly and you have a valid connection string, specifying a database user with sufficient rights the query works. One issue immediately apparent is the sensitive password information. This especially true if you intend to use this technique for automated batch jobs. To address the password issue we’ll need to encrypt the connection string and the store the password somewhere. Let’s a look at one solution…&lt;/p&gt;
&lt;h3&gt;Encrypting Connection Strings&lt;/h3&gt;
&lt;p&gt;Ideally everything would use Windows authentication and you wouldn’t need to store password information. The reality is this simple isn’t the case especially with Oracle databases. Unfortunately there aren’t any native encryption cmdlets in Powershell (I’d love to see a cmdlet that would use certificates in order to avoid pass phrases), there are however a very nice and set of Powershell encryption functions created by &lt;a href="http://lunex.spaces.live.com/default.aspx" target="_blank"&gt;Steven Hystad&lt;/a&gt; called &lt;a href="http://lunex.spaces.live.com/blog/cns!64CB3857E28BD106!344.entry" target="_blank"&gt;Library-StringCrytpo&lt;/a&gt;. &lt;/p&gt;
&lt;p&gt;To use the encryption functions download the Powershell script and source the library, then call the Write-EncryptedString function passing our connection string we want to encrypt with a passphrase. To decrypt the connection string call the Read-EncryptedString function with the encrypted string and passphrase.&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#006400;"&gt;#Source Encryption Functions&lt;/span&gt;            
&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;./Library-StringCrypto.ps1&lt;/span&gt;            
&lt;span style="color:#006400;"&gt;#encrypt string using passphrase&lt;/span&gt;            
&lt;span style="color:#ff4500;"&gt;$encrypt&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Write-EncryptedString&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$connString&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;4#&amp;amp;7yaoff&amp;quot;&lt;/span&gt;            
&lt;span style="color:#006400;"&gt;#Show encrypted string&lt;/span&gt;            
&lt;span style="color:#ff4500;"&gt;$encrypt&lt;/span&gt;            
&lt;span style="color:#006400;"&gt;#Decrypt string&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Read-EncryptedString&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$encrypt&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;4#&amp;amp;7yaoff&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The encrypt functions work well, but I like to do is then take the encrypted string and store it in a SQL Server table that is locked down. To do we’ll need to first create a table in SQL Server database as follows:&lt;/p&gt;
&lt;p&gt;&lt;font face="monospace"&gt;&lt;font color="#006633"&gt;&lt;b&gt;CREATE&lt;/b&gt;&lt;/font&gt; &lt;font color="#ffa500"&gt;TABLE&lt;/font&gt; [dbo].[server_lku](&lt;br /&gt;        [server_name] [&lt;font color="#60ff60"&gt;&lt;b&gt;varchar&lt;/b&gt;&lt;/font&gt;](&lt;font color="#ffa0a0"&gt;255&lt;/font&gt;) &lt;font color="#006633"&gt;&lt;b&gt;NOT&lt;/b&gt;&lt;/font&gt; &lt;font color="#ffa500"&gt;NULL&lt;/font&gt;,&lt;br /&gt;        [server_type] [&lt;font color="#60ff60"&gt;&lt;b&gt;varchar&lt;/b&gt;&lt;/font&gt;](&lt;font color="#ffa0a0"&gt;25&lt;/font&gt;) &lt;font color="#006633"&gt;&lt;b&gt;NOT&lt;/b&gt;&lt;/font&gt; &lt;font color="#ffa500"&gt;NULL&lt;/font&gt;,&lt;br /&gt;        [connection_string] [&lt;font color="#60ff60"&gt;&lt;b&gt;varchar&lt;/b&gt;&lt;/font&gt;](&lt;font color="#ffa0a0"&gt;2000&lt;/font&gt;) &lt;font color="#006633"&gt;&lt;b&gt;NOT&lt;/b&gt;&lt;/font&gt; &lt;font color="#ffa500"&gt;NULL&lt;/font&gt;,&lt;br /&gt;        [is_encrypted] [bit] &lt;font color="#006633"&gt;&lt;b&gt;NOT&lt;/b&gt;&lt;/font&gt; &lt;font color="#ffa500"&gt;NULL&lt;/font&gt;,&lt;br /&gt;CONSTRAINT [PK_server_lku] PRIMARY KEY CLUSTERED &lt;br /&gt;(&lt;br /&gt;        [server_name] &lt;font color="#ffa500"&gt;ASC&lt;/font&gt;&lt;br /&gt;)&lt;font color="#ffa500"&gt;WITH&lt;/font&gt; (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = &lt;font color="#ffa500"&gt;ON&lt;/font&gt;, ALLOW_PAGE_LOCKS  = &lt;font color="#ffa500"&gt;ON&lt;/font&gt;) &lt;font color="#ffa500"&gt;ON&lt;/font&gt; [PRIMARY]&lt;br /&gt;) &lt;font color="#ffa500"&gt;ON&lt;/font&gt; [PRIMARY]&lt;br /&gt;&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;font color="#006633"&gt;&lt;b&gt;SET&lt;/b&gt;&lt;/font&gt; ANSI_PADDING OFF&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;font color="#006633"&gt;&lt;b&gt;ALTER&lt;/b&gt;&lt;/font&gt; &lt;font color="#ffa500"&gt;TABLE&lt;/font&gt; [dbo].[server_lku] &lt;font color="#ffa500"&gt;ADD&lt;/font&gt;  CONSTRAINT [DF_server_lku_is_encrypted]  &lt;font color="#ffa500"&gt;DEFAULT&lt;/font&gt; ((&lt;font color="#ffa0a0"&gt;0&lt;/font&gt;)) &lt;font color="#ffa500"&gt;FOR&lt;/font&gt; [is_encrypted]&lt;br /&gt;GO&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Note: I&amp;#39;ve created the server_lku table on a server named win2k8r2\sql2k8 in the database dbautility &lt;/p&gt;
&lt;p&gt;In order to select and insert data into the server_lku table we’ll use the Get-SqlData and Set-SqlData functions from the LibrarySqlData script which I previously blogged about &lt;a href="http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!445.entry" target="_blank"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Source LibrarySqlData , and insert the encrypted string along with few other pieces of information into our SQL table using the Set-SqlData function. To retrieve the encrypted connect string use the Get-SqlData function and then call the Read-EncryptedString function.&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;./LibrarySqlData.ps1&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;set-sqldata&lt;/span&gt;  &lt;span style="color:#8b0000;"&gt;&amp;quot;win2k8r2\sql2k8&amp;quot;&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;dbautility&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;INSERT server_lku VALUES(&amp;#39;XE&amp;#39;,&amp;#39;oracle&amp;#39;,&amp;#39;$encrypt&amp;#39;,1)&amp;quot;&lt;/span&gt;            
&lt;span style="color:#006400;"&gt;#Retrive the unencrypted string&lt;/span&gt;            
&lt;span style="color:#ff4500;"&gt;$decryptedString&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Get-sqldata&lt;/span&gt;  &lt;span style="color:#8b0000;"&gt;&amp;quot;win2k8r2\sql2k8&amp;quot;&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;dbautility&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;SELECT * FROM server_lku where server_name = &amp;#39;XE&amp;#39;&amp;quot;&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#000000;"&gt;`
&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt; &lt;span style="color:#00008b;"&gt;if&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;is_encrypted&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;Read-EncryptedString&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;connection_string&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;4#&amp;amp;7yaoff&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#00008b;"&gt;else&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;connection_string&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
&lt;span style="color:#006400;"&gt;#Show decrypted string&lt;/span&gt;            
&lt;span style="color:#ff4500;"&gt;$decryptedString&lt;/span&gt;            
&lt;span style="color:#006400;"&gt;#Run query again&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;./Get-OLEDBData&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$decryptedString&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$qry&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Just as in our previous example all rows from the DEPARTMENTS table in the HR schema are returned:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mG1H6kchatcXM-wNXDAir8pRA6fiGL1kiPHGTE85JPO7BXAuSkuKzBsgNak-JTamjX3NVhDGVvTmSA_MY6lr6Dw7mu7qW3h6-6x9x21ed2WwMBgLLB9HvSWbw9wMsaqAzX96H-jfVJw9p738pm5C3-w/oraclePowershell22.jpg" rel="WLPP"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="oraclePowershell2" border="0" alt="oraclePowershell2" src="https://j2ttpq.blu.livefilestore.com/y1mxSwP-mgTnqcygxPMt-T75IEwSzncZomZV7Ovd2e4twlcmqlx7KTWsBK_wCTKSt6AKTH8DD9WzJdSAbUkum6ALIb6QQg6m58Pasao7D7YUXpDKFTq27DrpTSgg6vNmoKLveoEEQpzP4fCbrM-heeznQ/oraclePowershell2_thumb.jpg" width="244" height="174" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Querying Oracle databases from Powershell requires a little extra setup, but once you put these pieces in place you’re ready to start automating Oracle from Powershell!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;/p&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=18253" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/Oracle/default.aspx">Oracle</category></item><item><title>Querying Oracle from Powershell Part 1</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/03/01/querying-oracle-from-powershell-part-1.aspx</link><pubDate>Mon, 01 Mar 2010 09:48:00 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:18241</guid><dc:creator>cmille19</dc:creator><slash:comments>5</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=18241</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/03/01/querying-oracle-from-powershell-part-1.aspx#comments</comments><description>&lt;p&gt;In this two part blog post we will demonstrate how to query an Oracle database from Powershell. Before we can run queries against Oracle we need to install the Oracle client on our Windows machine. Unlike SQL Server, the drivers for connecting to Oracle are not included with the operating systems. The drivers are however freely available from Oracle. You can find the client software on the &lt;a href="http://www.oracle.com/technology/software/products/database/index.html" target="_blank"&gt;Oracle Database Software Downloads Page&lt;/a&gt;. &lt;/p&gt;
&lt;h3&gt;Downloading the Oracle Client&lt;/h3&gt;
&lt;p&gt;You’ll notice several versions of Oracle software on the download page. The software you choose will varying depending on your operating system. Generally when with dealing Oracle client software it is safe to choose the latest client version even if the Oracle database you will be connecting to is a lower version. &lt;/p&gt;
&lt;p&gt;At the time of this blog post the following versions were the latest available:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;11.1.0.7.0&lt;/strong&gt; Windows 2008 and Windows 2008 R2 &lt;/li&gt;
&lt;li&gt;&lt;strong&gt;11.1.0.6.0&lt;/strong&gt; Windows 2003 &lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;However, check &lt;a href="http://www.oracle.com/technology/software/products/database/index.html" target="_blank"&gt;the download page&lt;/a&gt; and choose a later version if listed. I’ve installed both the Windows 2008 and 2003 x64 versions, but for this blog series I’m using the Windows 2003 x64 version. To complete the download&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Select &lt;strong&gt;See All&lt;/strong&gt; &lt;/li&gt;
&lt;li&gt;Select &lt;strong&gt;Oracle Database 11g Release 1 Client (11.1.0.6.0) for Microsoft Windows (x64).&lt;/strong&gt; &lt;strong&gt;&lt;font color="#ff0000"&gt;Note: Be sure you select the Client download and not the full Oracle database software!&lt;/font&gt;&lt;/strong&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;font color="#000000"&gt;&lt;em&gt;Note: When you attempt to download Oracle software you will be prompted to login to the Oracle Technology Network (OTN). If you don’t have an account you’ll need to create one—It’s free.&lt;/em&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#000000"&gt;We’re now ready to install and configure the Oracle client software.&lt;/font&gt;&lt;/p&gt;
&lt;h3&gt;&lt;font color="#000000"&gt;Installing the Oracle Client&lt;/font&gt;&lt;/h3&gt;
&lt;p&gt;Many of the components included with the Oracle client are not needed. The following steps are used to perform a minimal Oracle client installation.&lt;/p&gt;
&lt;p&gt;Run setup.exe&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mW0XdCXGiWQrc0xRnjllczGw5YerMYbcw-tMbR0RIL5QsPyZGcqRPH2rdOcFu-NmhS8_f9QiMyA_e7ce7sDtlDtLwN0P_BnoguO46Cpo8vkOqcGnd00tzeM576FBJmOO4yLFhzCYE5lBPH7YDqqC9kw/oracleClient12.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient1" border="0" alt="oracleClient1" src="https://j2ttpq.blu.livefilestore.com/y1m3V1lb14egyZQyzIjagotYM_VLEkvZnEOOAZsixHLq7IDgd28yBZLCBaYHAkb5LIZvwhJphr1DAQb_WhAOfVRgHVK-ejOC3aSFIo6e-rGAOMGfTGoVwdVq7fZa2k7c4jaGfa11uQQ6WDHtZDMXOHudg/oracleClient1_thumb.jpg" width="244" height="89" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Click next on the Install Welcome Screen.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mgJCsvsQL_Fg--_nFTrRCvdc6GaygH-NHmkGGzWmE5KQNKvzUbfwav_LSDLOO4cZsL6L9cDq3_rSITX4S59Y0PxjMhp2i5JdAhBk7GrZFlh_wtBhlaGI5YAEVvaUMA65xW1_FHXlesgozIyR5lqpTXA/oracleClient22.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient2" border="0" alt="oracleClient2" src="https://j2ttpq.blu.livefilestore.com/y1mvbBQsiWkMwF86H2LgTgKANMnwwH49PGDdphEI_3UTQSsYUVSK5b2PU-kYct8Kw_x2ysS0qbvwfu8KZ9ngrQNaAIos5AwBVOD2qpkeMiW7wVJj9XMCmy8tbBZ1HFa4gaEiMqipCRgbnfxxAIDnLsCeA/oracleClient2_thumb.jpg" width="244" height="199" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select Custom installation type and click next.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1m-HhnqsdSwBAC3vmC6LA9Anm5lo4Kksy1qy8nIAC-zkl5KANVlxpgXrSC1rwsCe2QZQx8OQvf-oVn19F20sIzZKjODHATcu3FJqed2jAHjEu7SN74nzfMJ4fDWA8MgtLUhheY3-zx6Xc1yd5oR3G5LQ/oracleClient32.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient3" border="0" alt="oracleClient3" src="https://j2ttpq.blu.livefilestore.com/y1mIwZ77MtEQ3wlyT9UAsmY0p83blxU2lBAjmldgtcZagnFOfz3b3lmXKky1tJGYJevaITkaHSuAm-_L4yQ870Tquoj5xpaMYo2BTOWwmQWVmpWkzmoxyvfQk4i6kiubgkpsCVe6A1yajbRB0wIQCJqdw/oracleClient3_thumb.jpg" width="244" height="193" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The Oracle base directory should be off of a root drive of your choosing. I’m using C:\Oracle. Change the path and ensure the name field is auto populated correctly and then click next.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mJcKfsveWl7eqyqszmUDYRN0uVVk6cd2obMjYtxYSGTYpLvQbHLI_j8edflCV_3X6k0P3rwcJZLWY-D3m3YeWiwn2X116KXRFKEc4WbxLbYndIz8g3BmZKsABggl799shxPVpIN9MnVSYRnMt_pqagA/oracleClient42.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient4" border="0" alt="oracleClient4" src="https://j2ttpq.blu.livefilestore.com/y1mHB6va4n3zK_BLC1xqDK6yvT0rWEUU2O1I7lQpSwSg7obcyh2oHOzEyKTnb2a3wNN9GsZzfehYGGCMkHQ93QlOcj5-h8IDjKSN6Ur5Phl3Iotzz4Iilgp1xfo2a3qB1SwBEk4EP4uuXFyVOFaRXLp7w/oracleClient4_thumb.jpg" width="244" height="192" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Ensure all the requirement checks succeed and click next (Note: you may receive warnings on Windows 2008 R2 when using the Windows 2008 installation software. The install will still succeed even with these warnings).&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mYdT0TWmTO27SZhgMap1OdTISVtV0as0Ss31A0C7FR8EfMchMRNlHmCGsfd4lxVUiTCQr0K_ZxJ3f0yl-_zqZ_tEGwmG9KOir8pbHtosEigGTRjnS7XWFaSh4riQqFcDR8q6TjQOzG6d8_GblFfRviA/oracleClient52.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient5" border="0" alt="oracleClient5" src="https://j2ttpq.blu.livefilestore.com/y1myQYITaehqUdlwFbzi9Qf6mZOtkFg4YPwGOcmk7an5toNb7_fNvZmzcGdHdMO6wTmhX-8bRJEPA78CT5_vxVAhfKCg_8xPbPf_An12ex6WmeVbKW1t8d2T7-8GduTJmIkPid0kwYWbFtpnn3jZ0RAUQ/oracleClient5_thumb.jpg" width="244" height="191" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select SQL Plus and scroll down to select more components.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mkeh87aqlE3vHT86toF531N5R083I2gNcnrtXWlcvtRZ-pAoT4kEoGoCctPIZc2nv58toJczCy08kgNHJb8pWoEU8ENsQF6pSu2iucW4Mo-w39cq4QQipRDXlc3CtnzYCnP_7ob45jUbgQfIVn3QUrA/oracleClient62.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient6" border="0" alt="oracleClient6" src="https://j2ttpq.blu.livefilestore.com/y1m3jWSUe6t68aQ4CqcBoBGuwEFomayUZxoILSarqKSP_vyppx390uWG_XN9padKTEL-GYMmdby5cAoJZxX6SPyz4I4KlUc0aE-yQHqp1uckySOG-cZ3s4lBLGXl6cnKSrpSkRXjgLOCr_pQQJm9BT2Fg/oracleClient6_thumb.jpg" width="244" height="192" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select Oracle Windows Interfaces and ensure the first three components are &lt;strong&gt;NOT&lt;/strong&gt; selected. Ensure all other Windows Interface &lt;strong&gt;ARE&lt;/strong&gt; checked and scroll down to select additional components.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mmQaDrGZMReCODU85evvFwXkPQJpak66SUjslgx610Qi0BLI554l1dRMn6eqLruwx4w6zhVtDG75FpSgJ4sGX5AUsf8HCLJPq-V1sS_CjHik6dcbaIsZoD35zo88hqwnC9BK78atB-1udnfh8mr_WLQ/oracleClient72.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient7" border="0" alt="oracleClient7" src="https://j2ttpq.blu.livefilestore.com/y1m6rOL1S6zaqH4YskG12ffD9wpmrMLOq76XH-ZrPKsBaj7AJPu6J0NzkykW_tkVBmD9RyHbAuXlrukexdep9qRjSBa0yRurMx0lFlpWvcAtcl1pvFf39Vg2eu23iU98zCVexETm75W5ebxVbBUj6j9kA/oracleClient7_thumb.jpg" width="244" height="195" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select the Oracle Net component and click next.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mZf4g-RGDF98S8tXBKxw5P9ysEiCLM9I5iHkWiEq8xXHQbPBYe2EcF9Ku9ihgmFkiLUZh_COmPKoBHmbturaVhu5Tf1IR3vkH_JjCZXJgbNeDhzDeZ4nICMFkWhAUnKYfCXVzMq9GlhRbr6H7prx2Ag/oracleClient82.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient8" border="0" alt="oracleClient8" src="https://j2ttpq.blu.livefilestore.com/y1mV-GmSOm5EPMLldLMNjY-eica2HzU1up97s9BUEfrcbWR3pchtkzPJ5DVwUG5soPkVDXihGf0i8tbIVTqTDrcsGeEsqDA3ru6Ax44Lj8TCMhyEMySq8S0jvMaqp7CYVoWScu0J5Tiz9189KREI5RXMQ/oracleClient8_thumb.jpg" width="244" height="194" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select Install.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1m5dF7-Y6UFiC3MCw7H3M89sAgepwibW85EG0TM6rTjfYZiP6jiUeGKV4ZO0M7d01UY4p0rHV-xx2m-ryFsQrMOCooovlTRJysuJWKd-iOipAh5Ey3nErF6SqR5avoMK5d0eA4h48ei9LcR_vmRbiRTw/oracleClient92.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient9" border="0" alt="oracleClient9" src="https://j2ttpq.blu.livefilestore.com/y1m9739_pbW0kEwdCdUGy-zkI9eK3Gh1OfewzwDMiVj4WBkau1wpjyY2JnvXj7_PS8i0pw6a5C65lqKUO86NZAStB5TCQf5quQ_ExgTld1gqvIdSq1JKKk03d3w6d7WDUzbZPrCV-2EH7moI4_VJo1POw/oracleClient9_thumb.jpg" width="244" height="191" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Once the installation is complete the configuration utility will be launched by the installer.&lt;/p&gt;
&lt;h3&gt;Configuring the Oracle Client&lt;/h3&gt;
&lt;p&gt;Select next from the Oracle Net Configuration Assistant Welcome screen.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1m-EqAEcgRrNy2e_DqsjJi4WzRDQ7817cwMSJS0AxDjyk1r4_EosN3NG1XQf2lrPDpbOoyNRyuBS2qgMioCiJujgFs7gqkIarPekI6TNzdSe_MTXNcVb_qIY-bKXLAplkH8x9hTJ11MkE6youaicq7Xw/oracleClient102.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient10" border="0" alt="oracleClient10" src="https://j2ttpq.blu.livefilestore.com/y1mQUc0K_91OfEUa7cgIBUjApAV2cyjBlFOUNSgYEX6Z6HAImUg270lrC1SWb0NGTk-vLYQ9xpxxjamHgHSy26Ashld1-OXZ7NIky1e1YIT7dotQkVrS6pDziGCRXSRMR10fi-Gxdq3eBcsgyPeO3s2lw/oracleClient10_thumb.jpg" width="244" height="163" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select Next.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mpfbM5gXmGZY7u9TexOFDkbQkIzJPgzd6Di8aHwhSST4ePObhlKBOTb-mew0HvjlH687_eSpfWrlXbQBemmmc5k_uMnQMwmvjzSr0u3VPKGScOkOxK6eryr-2RlTBOY6qhFdZyW0-rGezThXShzGlGg/oracleClient112.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient11" border="0" alt="oracleClient11" src="https://j2ttpq.blu.livefilestore.com/y1mIyQRbJaYneO3NpleMxFbptssMUPlEx3Ix6l77Cr0VUXZfu-Wkhgpie0vokAI6LTaX7r3Yg5WOqziG96NDsN6D1bensv-X3lpY-KHrGEctezxaDIcFi8XWYTJDOjUfoR3OQMyCHzASv5fg7vbHWg0FQ/oracleClient11_thumb.jpg" width="244" height="161" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Enter the Oracle database service name. &lt;em&gt;Note: I’m using Oracle Express on Ubuntu Linux. The service name is XE, your service name may differ.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mYAAy8BIfxNwaMGllH8vvKH1Fr2caG_agvXMUMKT8dYi5x1VCY05YSeJjJogeV7UaPFEeh55UIIyqWqAiIAYzZhf9xkuCp_zjjdu7onRRjrFEjGzPf4uHIDCo3MCQAXFSfo8CMhGTZmbFtPe2o0HdEQ/oracleClient122.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient12" border="0" alt="oracleClient12" src="https://j2ttpq.blu.livefilestore.com/y1mWnP05BDBWGumAbK30dxJEJbjQUohDWxMeEWC58igC3n575KsxTp-fD5Zy6nyUtv9Mcpd5WghuarYXusIbVjYcR5evxy66SJRUG-79oFzqPHVs_CE94dhbVhW8YbmZk4XHwRjCoFL5dG23GnicH_ouA/oracleClient12_thumb.jpg" width="244" height="165" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Select Next.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1m_ATJFrJ9fkleIFyYlPa0HRucm3VCxC4PcRaJI0oPnE2UPVa4lVGZ7j780ZiIP2sPyY6EQkNSi4G7nPQED59Rxf2KJe6esUd1WwgjRUZGI0SRILifTktFhsf6ccwiiIvkoAndBxTfmFs2GA27_SWptQ/oracleClient132.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient13" border="0" alt="oracleClient13" src="https://j2ttpq.blu.livefilestore.com/y1mrP1VszvrnRGJs_qxcy09WbxcmyleMZBrKcL2yxsQPn85yZYaXZyVIhcxyoC4wq5ilt2WFlhZX6jlpu5OwUkVV3QpD3JuBRv_vcPrKsNRs7963CGTdVzRFh7QqNgmHYWbKUslQ7YhQCnO9hHitfUtgw/oracleClient13_thumb.jpg" width="244" height="163" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Enter the Oracle database server host name or IP address.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mZQ-iCCrOGfn4fTt9ZBbAHCQHaaHjPer19BZhPX8K-5mwX6Kg7yQjnb2fO_li0lGN6j1bM09Z55VPmLS5Z2ItgTZEdvwaAvKTRWO11Gnf_dWmfKncpym3zpdhH5yEXRQiXN5dyZg-C0e_Ax3zHCeAzg/oracleClient142.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient14" border="0" alt="oracleClient14" src="https://j2ttpq.blu.livefilestore.com/y1m7rfTKTi7QQiIgI_XK9Zfpy5gHDNiH0pK-ETpE9ZtcZFVe44znhlICpzcE_J3ySQNvHmV5FvnlZZ_LzquyOZFBq5o7i0d0aczPa3XqjBlJ005_8Dfa8HYM6syZiFZB_3pvAP-PjYoAGmHKTKXby292Q/oracleClient14_thumb.jpg" width="244" height="162" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select Next to test connectivity.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mD82CVomnHa3a3T-kEbCk59adkioMt3hge7yoglqWMCczUWsgRBY1U3JCOAORLTa9xKukU-ENczmNDsOpuNjHXWIp7maNT93_KB52uyMhNE0fUkQwzGnZ7lZ7cquj8Jw_AeYOawIfDeqH4dEitK9Nlw/oracleClient152.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient15" border="0" alt="oracleClient15" src="https://j2ttpq.blu.livefilestore.com/y1myU_VFIPhf22xJf8OCpr04DOEM-yQiESO58JRIZJjt4caCWYMm80h8v6Q6E_sQp3mYODiAskJRMcSBn8zez1bt9nOs_KT9QVfPIC1-veLI-AepDjTYHfKKi0YUEKgyOyp8PXNf46x-K8DoAfoxr3fHg/oracleClient15_thumb.jpg" width="244" height="165" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The test will fail, you’ll need to change the login and password by selecting Change Login&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mL3LbUeKYPKYJV8GCxj6WSxFYkdjEu47IBk7PnnefJIEGrUAu9hg_tnebaopuP4e6scwkfE5sXwzTFghzLnPDSho_I1Izfn-yHCiszHttQB5mfRkAEogK70h2iW3YnKfr1Yz_0dBf3sMkWL5ai4S8og/oracleClient162.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient16" border="0" alt="oracleClient16" src="https://j2ttpq.blu.livefilestore.com/y1me8kCIBfmZb2GDR-LShIHrPX1nUxy_o_XIqRnLheZqhj71rkqKvcleK_5SQFQ9xPD-QVCqO_1GO0S4IbfKDpO918Swu6RbxHTzW9mLi7ed6-LbocYwz4aSitGTm1MP68wTlN6TCfYL9u-nZZFjW4N4Q/oracleClient16_thumb.jpg" width="244" height="161" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;The test should succeed and if not use the error message to troubleshoot.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mO9hBdQnEZaHC2pyFfeL1zdfv34Fz8So1SNfkt6my7xG2TI-0bmev-N9g6BZnmXpKWLJ_3cbnBfwW0VJ-GBAMysvFKq7x3w_GPWqOyQOFKn4ChDOTOfZzpgWP-PA37dFIgzfyJ_QvQaPQnUVSRBbfqw/oracleClient172.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient17" border="0" alt="oracleClient17" src="https://j2ttpq.blu.livefilestore.com/y1mPNJ2D81w_ChO_dzXt9aWW-hX8JaJCJjnV-m5Rcb1HrASddlq3t5CUfyPutz7liTrYwwhXq3NWKW8XZhURSNgobCb600hH1GZhonU0a2e9IXoDQvCrV9Gi8l8IZk6xunnoKO2HOV9wP1W3oqHNmq2zA/oracleClient17_thumb.jpg" width="244" height="164" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Enter an alias name and select next.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mzGJ3LozBaMG1SGNW4RrZlmkN1lfWCk7n9fBguCEczk8WYqUqwpw-GPmlBiwlEK_hF6aiQvuR1tcVNoeXJKyZiYNHRuHaNpZvsNxwscJPFECbeNVpagbYKa_ls5JOChUW8JpUekuL8kxerRdzypjkjw/oracleClient182.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient18" border="0" alt="oracleClient18" src="https://j2ttpq.blu.livefilestore.com/y1mT-nkmpiW99GjURaYmdUt51mcRYZSANSo197sDT4E2i4NpCnmT4LCpTnS6LBm-sPTAyPVFZpr08XUJ1fGi12q_jrx6EvV_6nG-KuU9cTM9d66KWwH3HIcR90rQWVzGpbGObEMxPMn9MjNSvyeESVDgg/oracleClient18_thumb.jpg" width="244" height="160" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select Next.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mmKmu_dg7WtHpLCoM3m5LSioQnXWmE0_Wq4Uy5wZUsFXV1TzTKVRILUdXyn-xX3PIWWVjfxKI8zQnBVFHDVQFnDg_04zAColMdOCJZjXuVlwPQq2nGc6ETd6HHU0GeJ6ypT-meJpM6gFX34zWOtxyjQ/oracleClient192.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient19" border="0" alt="oracleClient19" src="https://j2ttpq.blu.livefilestore.com/y1mMrba8tkZyAwpyfson9yOays41aAO7-mT81Zbf6Aly3-XxQla7qNc3YocZD1eLva7o5xTf-Ve4x9giukiS8XfVEdli5LYHir8qn9cwc3YAsJHiy7Nt9OFksHIQGvSQ8NubFQVwn3WPhBuRxysZxNZYQ/oracleClient19_thumb.jpg" width="244" height="163" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Select Next.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1m7uwOsFPVYs4KLkTgfGg4zKy-ywMvs7oWpIoGR0LT85F9uZEukSFwUTnqcM6Us3Gmc5_6CYzQHeHWL_z-9YLg-srSLq9z7_qMYbDUdISxkrkLmAdcsZgfTbhPfR1K8AderM7BmFTLxhUZYs_psI-mCg/oracleClient202.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient20" border="0" alt="oracleClient20" src="https://j2ttpq.blu.livefilestore.com/y1m2RsIOs_0eCb5uehgNIGnKZS61kz1nssSLy14h511KQBixTNlz5WFaeky5nBJOsqgpPG6CUzb_Lmzkmyo66ybcHhOQil4_IrFTtgSNG4wjwONafciNEiFp4D5_5sM4-i6D64ZMRf9biAH6ZzH71xQpQ/oracleClient20_thumb.jpg" width="244" height="165" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select Next.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1m8yue5tcUwTtChU_Uy-jpeUnbGRNpi-3u-5O5-tjPzmvlrywwfC-rbEz6f5Yrl2euSuOyyE9YwLBLCNKFYVClDzAeUW97GqrvS4wVxMzIksqcULw0c_-4sfb8IXaQOLdyPIYVtcRkRPrc4vLUxfAWOw/oracleClient212.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient21" border="0" alt="oracleClient21" src="https://j2ttpq.blu.livefilestore.com/y1m_jviaDzKeaf9TqOZjVsJ6Ess22c2aDvsAVig04ggf4e_fFXkb-4uQ2cH5SdfP64IDjNUsnlpXTnNIYmuBaqnUIdpmvZ-hWHD3nG6DTU-65DTICa3QHHJYV_RQnrIH8z2BCKENCjIC2-ELFFvRmsERA/oracleClient21_thumb.jpg" width="244" height="163" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select Finish.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1m-ebrCN-FeCvzH-6ROzyVutzW5LkYct7KvtkbrkkflSWXn8jXuvwNK7DiQnEhFtlEvBjSASOOMgym6L3RSW6DqsTmeQddUmJg2UoxbQSGEi8NBYjQk_RN_AgKHIsSjVP0kqmO344xxZRbcWrZpPYBDw/oracleClient222.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient22" border="0" alt="oracleClient22" src="https://j2ttpq.blu.livefilestore.com/y1mrGly-W5zhfAp0QiurgQyXLhh1-iRPkcJH_JyP5DNXPL2Z3PH8z0r01CyOvB98ZtTwkW0hmeK0oIxTUf7e5WqN7BQXt-3955otEz-9YL7YnHKQvX8PEeM9iRQl6WsBTcYOMkP5TGOeFX3cVWLbjQIPg/oracleClient22_thumb.jpg" width="244" height="162" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select Exit.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mr7M3j9OqGf56GCJIeT3v-lG5RnU2KOhfHdY1q6NUspcZzLk-wnZNItXZzJ8zJVTK0aDvg3pSdc8D70qCvqpjNVLu6U_ajFcCpJsFEhQTBFQGBOdOW6u3VdWGCKz37whPtsJxWRYFUYM6ktA0dvg_SA/oracleClient232.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient23" border="0" alt="oracleClient23" src="https://j2ttpq.blu.livefilestore.com/y1m4RGDLhnlnIkXPRf86ptyiM_9qobXFnMB5Gi-EZOEc-Qnb7GuCgYlSkY7X2ftGDy-oJtR0KAlLHJnwOmKS5acMovPdZyrhC3DhPjaGyU2xfxgw1AWqgTPyoiI-JcIeCcp-86_N4bwvB__qUEWjMuatw/oracleClient23_thumb.jpg" width="244" height="191" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Select Yes.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mL6zzR9Em44IlaTHmZkVszXns8KNsRSJ3t1Uem9_ZS5paZKCy0Q3CfKaCiQgskppQfUDnLg135x3i7U9rTJiA9Tp1iUuoQpiBp1_l-NArUMSPpcjF-IKSnwykF96iV_jeoriPUfSGB_UwzJdMTnsnFQ/oracleClient242.jpg" rel="WLPP"&gt;&lt;img style="BORDER-RIGHT-WIDTH:0px;DISPLAY:inline;BORDER-TOP-WIDTH:0px;BORDER-BOTTOM-WIDTH:0px;BORDER-LEFT-WIDTH:0px;" title="oracleClient24" border="0" alt="oracleClient24" src="https://j2ttpq.blu.livefilestore.com/y1ml9sHumea6i21exMspWjIj7q2lyx1Mtgf7ObAP24305dP4RimKdcIMOskspcl0QuuPbjC1kjaAQp8WSkw-zefiabR0MqPyDwUoIgHW4nxjajqA6E2RVbJ66APQ_YRa3qjC-2xULDodJ-5Fz-l5uIAhQ/oracleClient24_thumb.jpg" width="244" height="189" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;Congratulations you’ve installed the Oracle client! My thanks to an Oracle colleague who wishes to remain anonymous. He was a big help with the installation and putting together this guide. In &lt;a class="null" href="http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!930.entry"&gt;part two&lt;/a&gt; of this blog series we’ll look at querying an Oracle database from Powershell.&lt;/p&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=18241" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/Oracle/default.aspx">Oracle</category></item><item><title>Suncoast Technology Forum Tech Fest Event 2010</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/02/26/suncoast-technology-forum-tech-fest-event-2010.aspx</link><pubDate>Fri, 26 Feb 2010 09:20:13 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:18187</guid><dc:creator>cmille19</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=18187</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/02/26/suncoast-technology-forum-tech-fest-event-2010.aspx#comments</comments><description> &lt;div&gt;I presented a 30 minute session at Suncoast Technology Forum Tech Fest on &lt;span style="font-family:Verdana, Arial, Helvetica, sans-serif;font-size:14px;"&gt;Windows Scripting Automation with Powershell&lt;/span&gt;: &amp;quot;This session will provide an introduction to Powershell for IT Pros seeking to automate administration tasks. Specific topics covered configuring Powershell, tips and tricks to help you get started with Powershell and writing simple scripts to automate everyday tasks.&amp;quot;&lt;/div&gt;&lt;div&gt; &lt;/div&gt;&lt;div&gt;The presentation and supporting materials are available here:&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;/div&gt; &lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=18187" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>The T-SQL Hammer</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/02/16/the-t_2D00_sql-hammer.aspx</link><pubDate>Wed, 17 Feb 2010 04:19:50 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:17859</guid><dc:creator>cmille19</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=17859</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/02/16/the-t_2D00_sql-hammer.aspx#comments</comments><description>  &lt;p&gt;The over-reliance on a familiar tool is best described with the quote, “if all you have is hammer, everything looks like nail” and for database professionals this means using or sometimes misusing T-SQL. Whenever database administrators are presented with a scripting problem they instinctively reach for good-old-familiar T-SQL.  And why not? In many cases T-SQL provides an ideal solution to SQL Server administration scripting problems, however there are certain scenarios where another tool, Powershell provides a  more elegant solution. &lt;/p&gt; &lt;p&gt;One such problem is scripting of database objects, T-SQL simply does not handle the complexities of objects script creation very well. In an attempt to use a familiar tool many people have written T-SQL scripts that trudge through system tables to produce an object creation script. The problem with such scripts is that they tend to be ugly, lengthy pieces of code that easily break. Experienced DBAs know querying system table directly is poor practice, yet they do it anyways in order to use their &lt;strike&gt;hammer&lt;/strike&gt; T-SQL tool. There’s a better way, &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.aspx" target="_blank"&gt;SQL Server Management Objects&lt;/a&gt; (SMO) has taken care of many of these issues for us and all we need to do is write a little Powershell code.&lt;/p&gt; &lt;p&gt;As an example let’s look at an object script problem from &lt;a href="http://www.brentozar.com/" target="_blank"&gt;Brent Ozar&lt;/a&gt;’s post, “&lt;a href="http://www.brentozar.com/archive/2010/02/how-to-really-compress-your-sql-server-backups/" target="_blank"&gt;How to REALLY Compress Your SQL Server Backups&lt;/a&gt;.” He describes a database size compression solution that does the following:&lt;/p&gt; &lt;ol&gt; &lt;li&gt;Script out all of the non-clustered indexes in the database  &lt;/li&gt;&lt;li&gt;Save those definitions to a table (or a stored procedure)  &lt;/li&gt;&lt;li&gt;Create a stored proc that will loop through those index definitions and recreate them later  &lt;/li&gt;&lt;li&gt;Drop the indexes&lt;/li&gt;&lt;/ol&gt; &lt;p&gt;Although Brent does not provide us with a script because in his words it’s a little duct-tape-y, he does link a to a couple of T-SQL based solutions:&lt;/p&gt; &lt;p&gt;&lt;a href="http://samsudeenb.blogspot.com/2007/11/scripts-to-drop-and-recreate-indexes-in.html" target="_blank"&gt;Scripts to Drop and ReCreate Indexes in SQL Server 2005&lt;/a&gt;&lt;/p&gt; &lt;p&gt;&lt;a href="http://www.sqlservercentral.com/scripts/Miscellaneous/31893/" target="_blank"&gt;SQL Server 2005: Script all Indexes&lt;/a&gt;&lt;/p&gt; &lt;p&gt;The authors of the T-SQL scripts use a classic SQL administration scripting technique of building code by interrogating various system tables. The scripts are not without issue. A quick glance at the &lt;a href="http://www.sqlservercentral.com/Forums/Topic401784-562-1.aspx" target="_blank"&gt;comment section of the second script&lt;/a&gt; reveals a dozen corrections were made to the original post after various users ran into things not accounted for. The abundance of corrections further illustrates T-SQL does not provide a good method to script out database objects. Now, let’s look at a more complete Powershell and SMO based solution.&lt;/p&gt; &lt;h4&gt;In order to store the index create and drop statements, we’ll need a table. I’m going to create the table in the same database:&lt;/h4&gt; &lt;p&gt;CREATE TABLE [dbo].[IndexDdl](&lt;br /&gt;    [DdlType] [varchar](10) NOT NULL,&lt;br /&gt;    [IndexScript] [varchar](4000) NOT NULL&lt;br /&gt;)  &lt;/p&gt;&lt;p&gt;SQL Server 2008 provides a Powershell interface accessible from SQL Server Management Studio. Start Powershell from the Tables folder in SQL Server Management Studio:&lt;/p&gt; &lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1m-30WsPf1potBk7xg9w0QtmyxNZqluZ5qyfTUg-0kcCR_I1jB_KuZr-HxJLxHeWlQzD2e45Q22ChMYB2IvImBD2XdHfwbur2EgrqQYxsslVcZOcO34i2C_BXD4AQJgDLUy0eK8pI5pJFli2Sofe3YUQ/startps0[2].jpg" rel="WLPP"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="startps0" border="0" alt="startps0" src="https://j2ttpq.blu.livefilestore.com/y1mHIFut93SGTnstI2e7ZlCFGMmgP4ElIN6dPA80nQqLBmkPuSTtzTRAfBD0fYyX-njaokdU-hSoNCG9xXOsbqg3Zs8Omcmdx11-kXklFx4BeyIB-lJHHk9iXlmdhNycFI6qL3F0vRgpAiMY2NdeL-HzQ/startps0_thumb.jpg" width="244" height="206" /&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt; &lt;a href="https://j2ttpq.blu.livefilestore.com/y1mFkpIojAH3oDludexr83eEUKJohdXMLhbM8rR_4UTMrKIfhhGhjL28oSkyQYT9dFeHlm8N-LQNi0EowEDVQP-48I3BxW7bBEzAhRwoLER5aCJU-OWmn5nDKqGfOGyFCTrsbIVgQwOW60VNnCuPQGm_Q/sqlpsidx[2].jpg" rel="WLPP"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="sqlpsidx" border="0" alt="sqlpsidx" src="https://j2ttpq.blu.livefilestore.com/y1mQQxxL-e0jAThXT5yE0uHq3FcPx0nP3UEA1tO_0q4ZiE6QbEPFUHCwIkdMuL3LkP7tI6mEG6Ut1gjKBjVbV6YCPW7Qinw_89r3hMc6Lrm7XHtBiX3H9RjMCBoKMUF2s8RXqiA-vGl2lA0E2DHIeeaaw/sqlpsidx_thumb.jpg" width="244" height="46" /&gt;&lt;/a&gt;&lt;/p&gt; &lt;h4&gt;Script out the non-clustered index drop statements and save them to the IndexDdl table:&lt;/h4&gt;&lt;pre&gt;&lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;New-Object&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Microsoft.SqlServer.Management.Smo.ScriptingOptions&lt;/span&gt;            
&lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;DdlHeaderOnly&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$true&lt;/span&gt;            
&lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;ScriptDrops&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$true&lt;/span&gt;            
            
&lt;span style="color:#0000ff;"&gt;dir&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;indexes&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;  &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;IsClustered&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$false&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-and&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;IsXmlIndex&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$false&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; `&lt;/pre&gt;&lt;pre&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;Script&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;invoke-sqlcmd&lt;/span&gt; &lt;span style="color:#000080;"&gt;-Query&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;INSERT dbo.IndexDdl VALUES(&amp;#39;Drop&amp;#39;,&amp;#39;$_&amp;#39;)&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Using the SQL Server Powershell provider, we are able to get all indexes that are non-clustered and not an XML index and then call the SMO &lt;i&gt;script &lt;/i&gt;method. Generating drop statements require a little extra setup in that we first need to create a &lt;i&gt;scripting options&lt;/i&gt; object and set the &lt;em&gt;DdlHeaderOnly&lt;/em&gt; and &lt;em&gt;ScriptDrops&lt;/em&gt; properties to true. The resulting script is then inserted into the &lt;em&gt;IndexDdl&lt;/em&gt; table. Note: Because the current connection is used the call to &lt;strong&gt;invoke-sqlcmd&lt;/strong&gt; does not specify a server or database name.&lt;/p&gt;
&lt;h4&gt;Script out the create index statements:&lt;/h4&gt;&lt;pre&gt;&lt;span style="color:#0000ff;"&gt;dir&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;indexes&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;  &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;IsClustered&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$false&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-and&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;IsXmlIndex&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$false&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; `&lt;/pre&gt;&lt;pre&gt;&lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;Script&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;invoke-sqlcmd&lt;/span&gt; &lt;span style="color:#000080;"&gt;-Query&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;INSERT dbo.IndexDdl VALUES(&amp;#39;Create&amp;#39;,&amp;#39;$_&amp;#39;)&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The create statement can use the default behavior of the &lt;em&gt;script&lt;/em&gt; method, no extra setup required.&lt;/p&gt;
&lt;h4&gt;To execute the drop statements:&lt;/h4&gt;&lt;pre&gt;&lt;span style="color:#ff4500;"&gt;$drops&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Invoke-sqlcmd&lt;/span&gt; &lt;span style="color:#000080;"&gt;-Query&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;SELECT IndexScript FROM dbo.IndexDdl WHERE DdlType = &amp;#39;Drop&amp;#39;&amp;quot;&lt;/span&gt;            
&lt;span style="color:#ff4500;"&gt;$drops&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;Invoke-sqlcmd&lt;/span&gt; &lt;span style="color:#000080;"&gt;-Query&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;$_.IndexScript&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;h4&gt;And finally if needed, to execute the create statements:&lt;/h4&gt;&lt;pre&gt;&lt;span style="color:#ff4500;"&gt;$creates&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Invoke-sqlcmd&lt;/span&gt; &lt;span style="color:#000080;"&gt;-Query&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;SELECT IndexScript FROM dbo.IndexDdl WHERE DdlType = &amp;#39;Create&amp;#39;&amp;quot;&lt;/span&gt;            
&lt;span style="color:#ff4500;"&gt;$creates&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;Invoke-sqlcmd&lt;/span&gt; &lt;span style="color:#000080;"&gt;-Query&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;$($_.IndexScript)&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;h3&gt;Observations&lt;/h3&gt;
&lt;p&gt;Although the command are run interactively the Powershell scripts can easily be incorporated into a SQL Server Agent Powershell step job. The solution works on down level versions of SQL Server as long as SMO 10 (SQL 2008) and sqlps (SQL Server Powershell) are available. The Powershell and SMO based solution is much less code, more easily understandable and since a standard SMO Script method is used, less prone to breakage. Not every SQL Server administration problem is a nail. Put down your T-SQL hammer and pick up Powershell!&lt;/p&gt;  &lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=17859" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/SMO/default.aspx">SMO</category></item><item><title>Providing Online Help for Powershell Modules</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/02/02/providing-online-help-for-powershell-modules.aspx</link><pubDate>Tue, 02 Feb 2010 11:24:27 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:17562</guid><dc:creator>cmille19</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=17562</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/02/02/providing-online-help-for-powershell-modules.aspx#comments</comments><description>&lt;p&gt;As a finishing touch for the &lt;a href="http://sqlpsx.codeplex.com/" target="_blank"&gt;SQL Server Powershell Extensions&lt;/a&gt; 2.0 Release I wanted to provide an online version of the help documentation I created from both comment-based and MAML formats. I had two requirements I need to be able to automatically convert comment-based and MAML-based help into static HTML pages and I need a free place to host the pages. The reason for the latter requirement is that I’m kind of lazy about web hosting. I don’t have my own server and I really don’t have a desire to have my own site--that’s part of the reason I blog at &lt;a href="http://chadwickmiller.spaces.live.com/"&gt;http://chadwickmiller.spaces.live.com&lt;/a&gt;. So I need to find a free static web hosting service. But, my first task is to automatically create HTML pages…&lt;/p&gt;
&lt;h3&gt;Generating Help HTML Pages&lt;/h3&gt;
&lt;p&gt;My favorite Powershell scripts are the ones I don’t have to write and a great place to find ready-to-use Powershell scripts is &lt;a href="http://poshcode.org/" target="_blank"&gt;PoshCode&lt;/a&gt; which hosts a repository of over 1,500 scripts. A quick search of PoshCode turned up a script called &lt;a href="http://poshcode.org/587" target="_blank"&gt;Out-Html by Vegard Hamar&lt;/a&gt; (whose script in turn is based on a script called Out-Wiki by Dimitry Sotnikov). The script converts help from pssnapin’s to HTML. I need to convert help for function and cmdlets within modules, so I performed &lt;a href="http://poshcode.org/1612" target="_blank"&gt;a minor edit of Out-Html&lt;/a&gt; PoshCode creates a new version of a Powershell script if you modify an existing one. If you do make a useful modification, please consider sharing. This goes for original scripts also.. To use Out-Html I need to import my modules: sqlserver, repl, Agent, SQLParser and ShowMbrs. Next modify the last line of the Out-html script to filter for these modules:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#0000ff;"&gt;Out-HTML&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;get-command&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;modulename&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;sqlserver&amp;#39;&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-or&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;modulename&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;repl&amp;#39;&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-or&lt;/span&gt; `&lt;/pre&gt;&lt;pre&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;modulename&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;Agent&amp;#39;&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-or&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;modulename&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;SQLParser&amp;#39;&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-or&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;modulename&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;SSIS&amp;#39;&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-or&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;modulename&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;ShowMbrs&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-and&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;commandtype&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-ne&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;Alias&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$outputDir&lt;/span&gt;            &lt;/pre&gt;
&lt;p&gt;Finally, run Out-Html:&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff"&gt;./Out-Html&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font color="#000000"&gt;And viola, 126 html files are produced in a folder named help under the current directory. The HTML files are pretty clean, but do contain a stray bracket, question mark and require some manual editing. Rather tweak the Out-Html script or mess around with Powershell I can easily fix all HTML documents using my favorite text editor, Vim:&lt;/font&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;font color="#000000"&gt;Select all htm files in Explorer and select edit with single Vim&lt;/font&gt; 
&lt;li&gt;&lt;font color="#000000"&gt;In command mode &lt;/font&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;div style="margin-right:0px;"&gt;&lt;font color="#00b0f0"&gt;args *.htm &lt;/font&gt;&lt;/div&gt;
&lt;div style="margin-right:0px;"&gt;&lt;font color="#00b0f0"&gt;argo %s/”&amp;lt;div&amp;gt;/&amp;lt;div&amp;gt;/ge | update&lt;/font&gt;&lt;/div&gt;
&lt;div style="margin-right:0px;"&gt;&lt;font color="#00b0f0"&gt;argo %s/&amp;lt;\/table&amp;gt;}/&amp;lt;\/table&amp;gt;/ge | update&lt;/font&gt;&lt;/div&gt;
&lt;div style="margin-right:0px;"&gt;&lt;font color="#000000"&gt;&lt;/font&gt; &lt;/div&gt;
&lt;p&gt;&lt;font color="#000000"&gt;If only Powershell ISE could do stuff like this, I might actually use it &lt;img title="Open-mouthed" style="vertical-align:middle;" height="19" alt="Open-mouthed" src="http://shared.live.com/rzvDQW1qjIikH13dsbM42g/emoticons/smile_teeth.gif" width="19" /&gt;. One other minor edit which I’ll explain in the next section, I need to rename default.htm to index.htm and index.html to default.htm. In addition, change the new index.htm line frame src=&amp;quot;./default.htm&amp;quot;. Having generated 126 HTML pages, I now need to find a place to host them...&lt;/font&gt;&lt;/p&gt;
&lt;h3&gt;Hosting Help HTML Pages&lt;/h3&gt;
&lt;div&gt;While searching for a place to plunk down my static we pages I found a blog post by &lt;a href="http://engelke.com/" target="_blank"&gt;Charles Engelke&lt;/a&gt; that describes how to use &lt;a href="http://blog.engelke.com/2008/07/30/google-appengine-for-web-hosting/" target="_blank"&gt;Google AppEngine for web hosting&lt;/a&gt; of static web pages--exactly what I’m looking for…&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;h4&gt;Setting Up a Google Application&lt;/h4&gt;
&lt;p&gt;To get started I had to perform a few setup tasks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://code.google.com/appengine/" target="_blank"&gt;Sign up for a Google App Engine account&lt;/a&gt;. As part of the sign up I picked &lt;strong&gt;sqlpsx&lt;/strong&gt; to be the application name. 
&lt;li&gt;Install the &lt;a href="http://www.activestate.com/activepython/downloads/" target="_blank"&gt;latest version of Python from ActiveState&lt;/a&gt;. In order to use the static web page hosting method Python is required. Now, I don’t know Python, but fortunately you don’t need to know how to write a single line of Python code to setup static web pages. 
&lt;li&gt;Download and install &lt;a href="http://code.google.com/appengine/downloads.html" target="_blank"&gt;Google App Engine SDK for Python&lt;/a&gt;. The SDK provides a GUI based utility for testing and deploying  a Google application.&lt;/li&gt;&lt;/li&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;h4&gt;Testing Google Application&lt;/h4&gt;
&lt;p&gt;To setup a test/deployment environment on my machine. First I created a directory &lt;strong&gt;C:\sqlpsx&lt;/strong&gt; and subdirectory static i.e. &lt;strong&gt;C:\sqlpsx\static.&lt;/strong&gt; I then moved all 126 htm files to the static directory.  Following Charles’ instructions I created an app.yaml file with the contents below and saved the file to &lt;strong&gt;C:\sqlpsx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="monospace"&gt;&lt;font color="#40ffff"&gt;application&lt;/font&gt;&lt;font color="#ffa500"&gt;:&lt;/font&gt; sqlpsx&lt;br /&gt;&lt;font color="#40ffff"&gt;version&lt;/font&gt;&lt;font color="#ffa500"&gt;:&lt;/font&gt; &lt;font color="#ffa0a0"&gt;1&lt;/font&gt;&lt;br /&gt;&lt;font color="#40ffff"&gt;runtime&lt;/font&gt;&lt;font color="#ffa500"&gt;:&lt;/font&gt; python&lt;br /&gt;&lt;font color="#40ffff"&gt;api_version&lt;/font&gt;&lt;font color="#ffa500"&gt;:&lt;/font&gt; &lt;font color="#ffa0a0"&gt;1&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#40ffff"&gt;handlers&lt;/font&gt;&lt;font color="#ffa500"&gt;:&lt;/font&gt;&lt;br /&gt;&lt;font color="#006633"&gt;&lt;b&gt;-&lt;/b&gt;&lt;/font&gt; &lt;font color="#40ffff"&gt;url&lt;/font&gt;&lt;font color="#ffa500"&gt;:&lt;/font&gt; (.&lt;font color="#60ff60"&gt;&lt;b&gt;*)/&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;  &lt;font color="#40ffff"&gt;static_files&lt;/font&gt;&lt;font color="#ffa500"&gt;:&lt;/font&gt; static&lt;font color="#006633"&gt;&lt;b&gt;\&lt;/b&gt;&lt;/font&gt;&lt;font color="#ffa0a0"&gt;1&lt;/font&gt;/index.htm&lt;br /&gt;  &lt;font color="#40ffff"&gt;upload&lt;/font&gt;&lt;font color="#ffa500"&gt;:&lt;/font&gt; static/index.htm&lt;br /&gt;&lt;br /&gt;&lt;font color="#006633"&gt;&lt;b&gt;-&lt;/b&gt;&lt;/font&gt; &lt;font color="#40ffff"&gt;url&lt;/font&gt;&lt;font color="#ffa500"&gt;:&lt;/font&gt; /&lt;br /&gt;  &lt;font color="#40ffff"&gt;static_dir&lt;/font&gt;&lt;font color="#ffa500"&gt;:&lt;/font&gt; static&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;The yaml file sets the index file as the default page which is why a swapped default and index file content as described earlier and also specifies the static directory. I’m now ready to test the application using SDK…&lt;/p&gt;
&lt;p&gt;Start Google App Engine Launcher which is part of the SDK installed earlier. From the File menu select “&lt;strong&gt;Add Existing Application&lt;/strong&gt;..” and navigate to the &lt;strong&gt;C:\sqlpsx&lt;/strong&gt; directory. Then click &lt;strong&gt;Run&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1m8UUoxZoLe8LBhTDAc5ncy6rFn57pIn29CNCVcEab5p2GuMAFkLSo5-nnqmg-gtSHq8UqxoybQ5dqKhxcZgyXZMAVWJwsvnW3QZzsSlJpdmrx54Ucb5obh6OUkneZLA-rBtD_EaHv0Inn6t-vRK9loQ/AppEngineLauncher[2].jpg" rel="WLPP"&gt;&lt;img title="AppEngineLauncher" style="border-right:0px;border-top:0px;display:inline;border-left:0px;border-bottom:0px;" height="120" alt="AppEngineLauncher" src="https://j2ttpq.blu.livefilestore.com/y1mmloNOUDZ_ti6tEj51lLQ9In75WU46em6YbChUiUh94Sm-gKWpaCaCNjsMD4TJCgP1c1qHYbyYk8pBeycbpQTJs-F60y2GY3PcW1iG0Rbd2zGlhoceF9QeH6vcGDG_jczSnUJtPXtMoadx7i2--z3cg/AppEngineLauncher_thumb.jpg" width="244" border="0" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;If everything is setup correctly clicking &lt;strong&gt;Browse&lt;/strong&gt; allows me to test the application locally before deploying. Eureka It Works!&lt;/p&gt;
&lt;h4&gt;Deploying Google Application&lt;/h4&gt;
&lt;p&gt;Finally deploying the application is as simple as clicking &lt;strong&gt;Deploy&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;SQLPSX Online Help&lt;/h3&gt;
&lt;p&gt;The website isn’t very pretty, but not bad for a few hours work. The online help site for SQL Server Powershell Extensions is available at &lt;a href="http://sqlpsx.appspot.com/"&gt;http://sqlpsx.appspot.com/&lt;/a&gt;. Enjoy!&lt;/p&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=17562" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>The Powershell V1 to V2 Conversion</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/02/01/the-powershell-v1-to-v2-conversion.aspx</link><pubDate>Mon, 01 Feb 2010 18:00:00 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:17412</guid><dc:creator>cmille19</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=17412</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/02/01/the-powershell-v1-to-v2-conversion.aspx#comments</comments><description>&lt;p&gt;This post is about my experience converting the CodePlex project, &lt;a href="http://sqlpsx.codeplex.com/" target="_blank"&gt;&lt;u&gt;&lt;font color="#800080"&gt;SQL Server Powershell Extensions&lt;/font&gt;&lt;/u&gt;&lt;/a&gt; (SQLPSX) Powershell V1 function libraries into PowerShell V2 Advanced functions within modules. &lt;/p&gt;
&lt;p&gt;In order to provide context for people reading this blog post a quick timeline is needed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Powershell V1 was released in November 2006&lt;/li&gt;
&lt;li&gt;SQLPS, the SQL Server Powershell host that ships with SQL Server 2008, is based on Powershell V1&lt;/li&gt;
&lt;li&gt;Powershell V2 was released in October 2009&lt;/li&gt;
&lt;li&gt;Everything you write in Powershell V1 should work in V2&lt;/li&gt;
&lt;li&gt;SQLPSX is a CodePlex project I started for working with SQL Server and Powershell. The first release was July 2008 and it has frequently updated since. A Powershell V2 release was published on 12/31/2009&lt;/li&gt;&lt;/ul&gt;
&lt;div&gt;And with that hopefully the rest of this post makes sense. Let&amp;#39;s take a look at my top six list of Powershell V2 improvements over V1 for script developers: &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;
&lt;h3&gt;&lt;strong&gt;Modules&lt;/strong&gt;&lt;/h3&gt;
&lt;div&gt;Modules allow a script developer to package functions, scripts, format files into something very easy to distribute. In Powershell V1 I would create a function library which is just a script file with related functions. The function library would then need to be sourced to use:&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;. ./librarySmo.ps1&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;There were several problems with this approach:&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Handling related related script files and separate function libraries is difficult -- usually solved by creating an initialization script and detailed instructions.&lt;/li&gt;
&lt;li&gt;Loading assemblies&lt;/li&gt;
&lt;li&gt;Appending format files&lt;/li&gt;&lt;/ul&gt;
&lt;div&gt;Modules make handling the distribution of a set of related files much easier. We simply place the module which is nothing more than the same old function library with .psm1 extension into a directory under Document\WindowsPowerShell\Modules and optionally add a second special file called module manifest (more on this later). As an example I have sqlserver module in a directory Document\WindowsPowerShell\Modules\sqlserver. I can then import a module instead of sourcing the functions:&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;import-module sqlserver&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt;&lt;/strong&gt; &lt;/div&gt;
&lt;div&gt;The module and manifest file contain the necessary information about processing assemblies, related script files, and nested modules. So, converting function libraries to modules involves little more than renaming .ps1 files to the module file extension .psm1 and placing the file into it&amp;#39;s own directory under Documents\WindowsPowershell\Modules. But, if that&amp;#39;s all you are going to do there is little value in creating modules. Moving from Powershell V1 scripts to V2 modules should also include taking advantage of many of the Powershell V2 features described in this blog post.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;A word about binary modules:&lt;/strong&gt; SQLPSX is mostly implemented as Powershell script modules there are however a couple of compiled cmdlets used for parsing and formatting of T-SQL scripts: Test-SqlScript and Out-Sqlscript. Converting compiled snapin dll&amp;#39;s to a module is just as easy as script based function libraries, you simply copy the snapin dll and any required assemblies to its own directory under DocumentsWindowsPowershell\Modules. This is exactly what I&amp;#39;ve done with the SQLParser module. I&amp;#39;ve also added a module manifest (psd1 file).&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;This brings us to module manifests which are basically processing instructions for moduels. Module manifests (psd1) files are created by &lt;strong&gt;new-modulemanifest&lt;/strong&gt; cmdlet allow us to do several things:&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Make functions private through by pattern matching the FunctionsToExport property. As an example in the SQLServer module I specify &lt;strong&gt;FunctionsToExport = &amp;#39;*-SQL*&amp;#39; &lt;/strong&gt;-- This tell Powershell to only export function that match -SQL prefix. I have several helper functions that I don&amp;#39;t want to export, so I simply use a different prefix or none at all to avoid exporting.&lt;/li&gt;
&lt;li&gt;Import assemblies automatically by making use of the &lt;strong&gt;RequiredAssemblies &lt;/strong&gt;property&lt;/li&gt;
&lt;li&gt;Nest modules i.e. import child modules with &lt;strong&gt;NestedModules &lt;/strong&gt;property&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;The manifest files themselves are really easy to create. After you&amp;#39;ve created a module (.psm1), run new-modulemanifest and enter the information when prompted.&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;Simplified Error Checking&lt;/strong&gt;&lt;/h3&gt;&lt;/div&gt;
&lt;div&gt;The try/catch error handling added to Powershell V2 is so much easier to work with and understand than its predecessor in Powershell V1 trap and thow. The construct is especially handy when dealing with &lt;a href="http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!458.entry" target="_blank"&gt;SMO errors that sometimes use nested error objects&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Both validatescript and validateset reduce input validation code I needed to write. I think this is best illustrated by a couple of examples from SQLPSX functions&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;The param section below uses ValidateSet to ensure values are either Data or Log:&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#00008b;"&gt;&lt;/span&gt; &lt;/div&gt;
&lt;div&gt;&lt;span style="color:#00008b;"&gt;param&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;            &lt;br /&gt;    &lt;span style="color:#a9a9a9;"&gt;[&lt;/span&gt;&lt;span style="color:#add8e6;"&gt;Parameter&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;Position&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#800080;"&gt;0&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#000000;"&gt;Mandatory&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$true&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;]&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$sqlserver&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt;            &lt;br /&gt;    &lt;span style="color:#a9a9a9;"&gt;[&lt;/span&gt;&lt;span style="color:#add8e6;"&gt;ValidateSet&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#8b0000;"&gt;&amp;quot;Data&amp;quot;&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;Log&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;]&lt;/span&gt;            &lt;br /&gt;    &lt;span style="color:#a9a9a9;"&gt;[&lt;/span&gt;&lt;span style="color:#add8e6;"&gt;Parameter&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;Position&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#800080;"&gt;1&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#000000;"&gt;Mandatory&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$true&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;]&lt;/span&gt; &lt;span style="color:#008080;"&gt;[string]&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$dirtype&lt;/span&gt;            &lt;br /&gt;    &lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#00008b;"&gt;&lt;/span&gt; &lt;/div&gt;
&lt;div&gt;&lt;span style="color:#00008b;"&gt;&lt;font color="#000000"&gt;This second param section uses ValidateScript to check that the input object namespace is an SMO object.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;pre&gt;&lt;span style="color:#00008b;"&gt;param(&lt;/span&gt;            
  &lt;span style="color:#a9a9a9;"&gt;[&lt;/span&gt;&lt;span style="color:#add8e6;"&gt;Parameter&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;Position&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#800080;"&gt;0&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#000000;"&gt;Mandatory&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$true&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#000000;"&gt;ValueFromPipeline&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$true&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;]&lt;/span&gt;            
  &lt;span style="color:#a9a9a9;"&gt;[&lt;/span&gt;&lt;span style="color:#add8e6;"&gt;ValidateScript&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;GetType&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;Namespace&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-like&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;Microsoft.SqlServer.Management.Smo*&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;]&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$smo&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt;            
  &lt;span style="color:#a9a9a9;"&gt;[&lt;/span&gt;&lt;span style="color:#add8e6;"&gt;Parameter&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;Position&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#800080;"&gt;1&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#000000;"&gt;Mandatory&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$false&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;]&lt;/span&gt; &lt;span style="color:#008080;"&gt;[Microsoft.SqlServer.Management.Smo.ScriptingOptions]&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;New-SqlScriptingOptions&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
  &lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;Between ValidateSet and ValidateScript I&amp;#39;m able to handle most input validation checks that in Powershell V1 would have required more code.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;h3&gt;&lt;strong&gt;Testing&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;OK, so this items really isn&amp;#39;t about Powershell V2 rather it&amp;#39;s a change in process for me. As part of the conversion I wanted to adopt a testing framework and perform more rigorous testing. I first heard of a Powershell based xUnit testing framework on the &lt;a href="http://powerscripting.wordpress.com/2009/08/16/episode-80-klaus-graefensteiner/" target="_blank"&gt;Powerscripting podcast episode 80&lt;/a&gt; in which Jon and Hal interviewed  &lt;a href="http://tellingmachine.com/" target="_blank"&gt;Klaus Graefensteiner&lt;/a&gt; about his CodePlex project &lt;a href="http://psunit.codeplex.com/" target="_blank"&gt;PSUnit&lt;/a&gt;. So, I decided to try PSUnit and I&amp;#39;ve been very happy with the results. Following the directions on the PSUnit site it is a cinch to setup. PSUnit integrates with Powershell ISE. A menu item is added to execute Unit tests:&lt;/p&gt;
&lt;p&gt;&lt;a href="https://j2ttpq.blu.livefilestore.com/y1mgDhKZrGdxzLhTW16cScb64KpFTTfO9lrjNTTjTGXX_NNPiGS0-TW2ZAXgKwmYHT-OipFV4lwcahdWqTHFqp-oSOPbi6PlETiKoFRA5SCeH1-XYhlRDiWmzvcmQiHzPEtOQAwIrhSUoS6VFROR4biEQ/PSUnit0.png" target="_blank" rel="WLPP;url=https://j2ttpq.blu.livefilestore.com/y1mgDhKZrGdxzLhTW16cScb64KpFTTfO9lrjNTTjTGXX_NNPiGS0-TW2ZAXgKwmYHT-OipFV4lwcahdWqTHFqp-oSOPbi6PlETiKoFRA5SCeH1-XYhlRDiWmzvcmQiHzPEtOQAwIrhSUoS6VFROR4biEQ/PSUnit0.png"&gt;&lt;img alt="" src="https://j2ttpq.blu.livefilestore.com/y1mgDhKZrGdxzLhTW16cScb64KpFTTfO9lrjNTTjTGXX_NNPiGS0-TW2ZAXgKwmYHT-OipFV4lwcahdWqTHFqp-oSOPbi6PlETiKoFRA5SCeH1-XYhlRDiWmzvcmQiHzPEtOQAwIrhSUoS6VFROR4biEQ/PSUnit0.png" /&gt;&lt;/a&gt; &lt;/p&gt;
&lt;p&gt;It should be noted that although I&amp;#39;m using PSUnit to test Powershell functions this doesn&amp;#39;t mean that&amp;#39;s all its good for. In fact the purpose of the PSUnt is to perform full unit testing of your .NET applications. You can test just about anything (.NET, COM, etc). For my purposes I&amp;#39;m interested in testing my own Powershell functions.  As a script developer the easiest thing you can do with PSUnit is to create a test function for each of your functions and verify the output object is the type you expected. Here&amp;#39;s an example test function for Get-SqlServer:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#00008b;"&gt;function&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Test.Get-SqlServer&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#008080;"&gt;[switch]&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$Category_GetSql&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
&lt;span style="color:#000000;"&gt;{&lt;/span&gt;            
    &lt;span style="color:#006400;"&gt;#Arrange&lt;/span&gt;            
    &lt;span style="color:#006400;"&gt;#Act&lt;/span&gt;            
    &lt;span style="color:#ff4500;"&gt;$Actual&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Get-SqlServer&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;$env:computername\sql2K8&amp;quot;&lt;/span&gt;            
    &lt;span style="color:#0000ff;"&gt;Write-Debug&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$Actual&lt;/span&gt;            
    &lt;span style="color:#006400;"&gt;#Assert&lt;/span&gt;            
    &lt;span style="color:#0000ff;"&gt;Assert-That&lt;/span&gt; &lt;span style="color:#000080;"&gt;-ActualValue&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$Actual&lt;/span&gt; &lt;span style="color:#000080;"&gt;-Constraint&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$ActualValue&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;GetType&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;Name&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &amp;#39;&lt;span style="color:#8b0000;"&gt;&lt;font color="#000000"&gt;Server&amp;#39;&lt;/font&gt;&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div&gt;Althought most of the test functions I&amp;#39;ve created verify the object type. Of course you can develop more complex assertions.  This approach works very well for SQLPSX functions that return SMO objects like server, database, table, etc. The samples and documentation for PSUnit have additional examples. Once you create test functions you can easily test and repeat in a matter of minutes. The first time I ran through a complete test I had a failure rate around 10% of all functions. This means that 10% of the function never really worked. I thought I had tested everything, but without a framework in place things get missed. As part of the release I made sure every function tested and passed 100%. I really like the HTML reports PSUnit generates. Sample output from a test of the SQLServer module is available &lt;a href="http://cid-ea42395138308430.skydrive.live.com/embedicon.aspx/Public/Blog/PSUnitTestReport^_Test.SQLServer.ps1^_2009-12-30-20-49-12^_T69P67F2S0.html" target="_blank"&gt;here&lt;/a&gt;. All SQLPSX test scripts are available in the &lt;a href="http://sqlpsx.codeplex.com/SourceControl/list/changesets" target="_blank"&gt;source code area under &amp;quot;Test Scripts&amp;quot;&lt;/a&gt;. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Big thanks to Klaus for creating PSUnit, I&amp;#39;m looking forward to seeing the soon-to-be release version 2.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;h3&gt;&lt;strong&gt;Process from Pipeline&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Embracing the pipeline is part of writing Powershell scripts to be well, more Powershell-like. In Powershell V1 I adopted a style of writing functions created &lt;a href="http://keithhill.spaces.live.com/default.aspx" target="_blank"&gt;Keith Hill&lt;/a&gt; as described in his blog post titled &amp;quot;&lt;a href="http://keithhill.spaces.live.com/blog/cns!5A8D2641E0963A97!595.entry" target="_blank"&gt;Writing CMDLETs in PowerShell&lt;/a&gt;&amp;quot;. The post shows us how to write functions to accept both command argument and pipeline input. Powershell V2 makes creating a function to accept both command argument and pipeline even easier. As example let&amp;#39;s look at a Powershell V1 function and the equivalent Powershell V2 function:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#00008b;"&gt;&lt;font color="#000000"&gt;Powershell V1 function:&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color:#00008b;"&gt;function&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Get-SqlScripter&lt;/span&gt;            
&lt;span style="color:#000000;"&gt;{&lt;/span&gt;            
    &lt;span style="color:#00008b;"&gt;param&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$smo&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;Set-SqlScriptingOptions&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
    &lt;span style="color:#00008b;"&gt;begin&lt;/span&gt;            
    &lt;span style="color:#000000;"&gt;{&lt;/span&gt;            
        &lt;span style="color:#00008b;"&gt;function&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Select-SqlScripter&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$smo&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;Set-SqlScriptingOptions&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
        &lt;span style="color:#000000;"&gt;{&lt;/span&gt;            
            &lt;span style="color:#ff4500;"&gt;$smo&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;Script&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
            
        &lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#006400;"&gt;#Select-SqlScripter&lt;/span&gt;            
    &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
    &lt;span style="color:#00008b;"&gt;process&lt;/span&gt;            
    &lt;span style="color:#000000;"&gt;{&lt;/span&gt;            
        &lt;span style="color:#00008b;"&gt;if&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
        &lt;span style="color:#000000;"&gt;{&lt;/span&gt;            
            &lt;span style="color:#00008b;"&gt;if&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;GetType&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;Namespace&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-like&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;Microsoft.SqlServer.Management.Smo*&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
            &lt;span style="color:#000000;"&gt;{&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Write-Verbose&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;Get-SqlScripter $($_.Name)&amp;quot;&lt;/span&gt;            
              &lt;span style="color:#0000ff;"&gt;Select-SqlScripter&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt; &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
            &lt;span style="color:#00008b;"&gt;else&lt;/span&gt;            
            &lt;span style="color:#000000;"&gt;{&lt;/span&gt; &lt;span style="color:#00008b;"&gt;throw&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;Get-SqlScripter:Param `$smo must be an SMO object.&amp;#39;&lt;/span&gt; &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
            
        &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
    &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
    &lt;span style="color:#00008b;"&gt;end&lt;/span&gt;            
    &lt;span style="color:#000000;"&gt;{&lt;/span&gt;            
        &lt;span style="color:#00008b;"&gt;if&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$smo&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
        &lt;span style="color:#000000;"&gt;{&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$smo&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Get-SqlScripter&lt;/span&gt; &lt;span style="color:#000080;"&gt;-scriptingOptions&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt; &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
    &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
            
&lt;span style="color:#000000;"&gt;}&lt;/span&gt;             
            
&lt;span style="color:#00008b;"&gt;&lt;font color="#000000"&gt;Powershell V2 function:&lt;/font&gt;&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color:#00008b;"&gt;function&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Get-SqlScripter&lt;/span&gt;            
&lt;span style="color:#000000;"&gt;{&lt;/span&gt;            
    &lt;span style="color:#00008b;"&gt;param&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;            
    &lt;span style="color:#a9a9a9;"&gt;[&lt;/span&gt;&lt;span style="color:#add8e6;"&gt;Parameter&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;Position&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#800080;"&gt;0&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#000000;"&gt;Mandatory&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$true&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#000000;"&gt;ValueFromPipeline&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$true&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;]&lt;/span&gt;            
    &lt;span style="color:#a9a9a9;"&gt;[&lt;/span&gt;&lt;span style="color:#add8e6;"&gt;ValidateScript&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;GetType&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;Namespace&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-like&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;Microsoft.SqlServer.Management.Smo*&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;]&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$smo&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt;            
    &lt;span style="color:#a9a9a9;"&gt;[&lt;/span&gt;&lt;span style="color:#add8e6;"&gt;Parameter&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;Position&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#800080;"&gt;1&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#000000;"&gt;Mandatory&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$false&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;]&lt;/span&gt; &lt;span style="color:#008080;"&gt;[Microsoft.SqlServer.Management.Smo.ScriptingOptions]&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt;&lt;span style="color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;New-SqlScriptingOptions&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
    &lt;span style="color:#000000;"&gt;)&lt;/span&gt;            
            
    &lt;span style="color:#00008b;"&gt;process&lt;/span&gt;            
    &lt;span style="color:#000000;"&gt;{&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$smo&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;Script&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$scriptingOptions&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
            
&lt;span style="color:#000000;"&gt;}&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;&lt;span style="color:#000000;"&gt;The functions can be called from the pipeline:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000000;"&gt;&lt;em&gt;Get-SqlDatabase &amp;quot;Z002\sql2k8&amp;quot; &amp;quot;pubs&amp;quot; | Get-SqlTable -name &amp;quot;authors&amp;quot; | Get-SqlScripter&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt; &lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000000;"&gt;OR as a command line argument&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000000;"&gt;&lt;em&gt;$table = Get-SqlDatabase &amp;quot;Z002\sql2k8&amp;quot; &amp;quot;pubs&amp;quot; | Get-SqlTable -name &amp;quot;authors&amp;quot;&lt;/em&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000000;"&gt;&lt;em&gt;Get-SqlScripter $table &lt;/em&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000000;"&gt;&lt;/span&gt; &lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000000;"&gt;Both functions perform the same function, however the Powershell V2 function is much simpler due to the use of &amp;quot;ValueFromPipeLine&amp;quot; this tells Powershell to accept input from the pipeline and the command line without a lot of extra coding.&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;Help&lt;/strong&gt;&lt;/h3&gt;
&lt;div&gt;The ability to add comment-based to a function is huge benefit in usability. Prior to Powershell V2&amp;#39;s release I contemplated creating compiled cmdlets just so help would be available--I&amp;#39;m glad I waited. There are two ways to create help for scripts you can either use comment-based help or use an external MAML file (for compiled cmdlets MAML files are your only option). I &lt;a href="http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!542.entry" target="_blank"&gt;briefly toyed with the idea of using External MAML files&lt;/a&gt; for scripts however there are limitations in needing to specify an absolute path plus MAML files are bit unwieldy to create. My advice if you&amp;#39;re going to create help for scripts or functions use comment-based help. The syntax for comment based help is very simple. Here&amp;#39;s an example comment-based help from SQLPSX:&lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;&lt;font color="#80a0ff"&gt;&amp;lt;#&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffa500"&gt;.SYNOPSIS&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;Scripts an SMO object.&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffa500"&gt;.DESCRIPTION&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;The Get-SqlScripter function  calls the script method for an SMO object(s).&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffa500"&gt;.INPUTS&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;Microsoft.SqlServer.Management.Smo.*&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;    You can pipe SMO objects to Get-SqlScripter &lt;/font&gt;&lt;br /&gt;&lt;font color="#ffa500"&gt;.OUTPUTS&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;System.String&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;    Get-SqlScripter returns an array System.String.&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffa500"&gt;.EXAMPLE&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;Get-SqlDatabase &amp;quot;Z002\sql2k8&amp;quot; &amp;quot;pubs&amp;quot; | Get-SqlTable | Get-SqlScripter&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;This command scripts out all user tables in the pubs database.&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffa500"&gt;.EXAMPLE&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;Get-SqlDatabase &amp;quot;Z002\sql2k8&amp;quot; &amp;quot;pubs&amp;quot; | Get-SqlTable -name &amp;quot;authors&amp;quot; | Get-SqlScripter&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;This command scripts out the authors table.&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffa500"&gt;.EXAMPLE&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;$scriptingOptions = New-SqlScriptingOptions&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;$scriptingOptions.Permissions = $true&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;$scriptingOptions.IncludeIfNotExists = $true&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;Get-SqlDatabase &amp;quot;Z002\sql2k8&amp;quot; &amp;quot;pubs&amp;quot; | Get-SqlTable | Get-SqlScripter -scriptingOptions $scriptingOptions&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;This command scripts out all users tables in the pubs database and passes a scriptingOptions.&lt;/font&gt;&lt;br /&gt;&lt;font color="#ffa500"&gt;.LINK&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;Get-SqlScripter &lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;New-SqlScriptingOptions&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;#&amp;gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#006633"&gt;&lt;b&gt;function&lt;/b&gt;&lt;/font&gt; &lt;font color="#40ffff"&gt;Get-SqlScripter&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;I can then use &lt;a href="http://sqlpsx.appspot.com/Get-SqlScripter.htm" target="_blank"&gt;&lt;u&gt;&lt;font color="#0066cc"&gt;get-help Get-SqlScripter -full &lt;/font&gt;&lt;/u&gt;&lt;/a&gt;to show help output with examples. I wish I could use comment-based help instead of MAML for compiled cmdlets! &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;h3&gt;&lt;strong&gt;new-object -property hashtable&lt;/strong&gt;&lt;/h3&gt;
&lt;div&gt;One of great things about Powershell is the discoverability of objects. If you create a new object you can instantly see the objects properties and methods using Get-Member. Only one problem, the discoverability aspect tends to break down when the creators of the object model you&amp;#39;re using make bad design decisions, case in point the &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.sqlserver.replication.scriptoptions(SQL.90).aspx" target="_blank"&gt;Microsoft.SqlServer.Replication.ScriptOptions&lt;/a&gt;. This enumeration uses a &lt;a href="http://msdn.microsoft.com/en-us/library/system.flagsattribute.aspx" target="_blank"&gt;FlagsAttribute&lt;/a&gt; to allow bitwise combination of attributes. If this sounds confusing, it is. Fortunatley Powershell V2 adds a very clean way of &lt;a href="http://blogs.msdn.com/powershell/archive/2009/12/05/new-object-psobject-property-hashtable.aspx" target="_blank"&gt;creating objects that allow you to specify a hashtable as input&lt;/a&gt;. We can leverage this feature to create a more intuitive replication script options object. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;First I created a file &lt;font color="#8b0000"&gt;replscriptopts.ps1 &lt;/font&gt;with a hashtable of all the replication scrpting options, a subset is included below:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;@{&lt;br /&gt;Deletion = $false&lt;br /&gt;Creation = $true&lt;br /&gt;DisableReplicationDB = $false&lt;br /&gt;EnableReplicationDB = $false&lt;br /&gt;IncludeAgentProfiles = $false&lt;br /&gt;} &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Next I create a function which creates an object from the file:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;span style="color:#0000ff;"&gt;function New-ReplScriptOptions&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#0000ff;"&gt;&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;{&lt;/span&gt;&lt;/div&gt;&lt;pre&gt;&lt;span style="color:#0000ff;"&gt;new-object&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;PSObject&lt;/span&gt; &lt;span style="color:#000080;"&gt;-property&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;&amp;amp;&lt;/span&gt;&lt;span style="color:#8b0000;"&gt;&amp;quot;$scriptRoot\replscriptopts.ps1&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;add-member&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;scriptproperty&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;ScriptOptions&lt;/span&gt; &lt;span style="color:#000000;"&gt;`
&lt;/span&gt;&lt;span style="color:#000000;"&gt;{&lt;/span&gt;            
  &lt;span style="color:#ff4500;"&gt;$scriptOptions&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#008080;"&gt;[Microsoft.SqlServer.Replication.ScriptOptions]&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;::&lt;/span&gt;&lt;span style="color:#000000;"&gt;None&lt;/span&gt;            
  &lt;span style="color:#ff4500;"&gt;$this&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;get-member&lt;/span&gt; &lt;span style="color:#000080;"&gt;-type&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;NoteProperty&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$this&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;name&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt;             
          &lt;span style="color:#0000ff;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$scriptOptions&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$scriptOptions&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-bor&lt;/span&gt; &lt;span style="color:#008080;"&gt;[Microsoft.SqlServer.Replication.ScriptOptions]&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;::&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;name&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;            
  &lt;span style="color:#ff4500;"&gt;$scriptOptions&lt;/span&gt;            
&lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#000080;"&gt;-passthru&lt;/span&gt;&lt;/pre&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;}&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;&lt;/span&gt; &lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;&lt;font color="#000000"&gt;The function, new-replscriptoptions creates a new object using a hashtable as input. The add-member portion adds a scriptproperty that calculates the bitwise representation of all properties where the value is set to true. So, rather than the bizare bitwise enumeration we started out with we now have a discoverable object.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;&lt;em&gt;&lt;font color="#000000"&gt;&lt;/font&gt;&lt;/em&gt;&lt;/span&gt; &lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;&lt;font color="#000000"&gt;I can then create a replication script options object and set the properties I wanted turned on to true and then use the object to script out my replication.&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;&lt;font color="#000000"&gt;&lt;em&gt;$scriptOpt = new-replscriptopts&lt;/em&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;&lt;font color="#000000"&gt;&lt;em&gt;$scriptOpt.Deletion = $true&lt;/em&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;&lt;font color="#000000"&gt;&lt;em&gt;$scriptOpt.Creation = $true&lt;/em&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;&lt;font color="#000000"&gt;&lt;em&gt;#Returns bitwise combination of properties&lt;/em&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#000080;"&gt;&lt;font color="#000000"&gt;&lt;em&gt;$scriptOpt.ScriptOptions&lt;/em&gt;&lt;/font&gt;&lt;/span&gt;&lt;/div&gt;&lt;/span&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;h3&gt;&lt;strong&gt;Gotchas&lt;/strong&gt;&lt;/h3&gt;
&lt;div&gt;A few issues I ran into during the conversion and remembered to write down...&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Cannot find type for custom attribute &amp;#39;Parameter &amp;#39;. Please make sure the assembly containing this type is loaded. Used &lt;a href="http://richardsiddaway.spaces.live.com/blog/cns!43CFA46A74CF3E96!2089.entry" target="_blank"&gt;this post&lt;/a&gt; from &lt;a href="http://richardsiddaway.spaces.live.com/" target="_blank"&gt;Richard Siddaway&lt;/a&gt; to resolve&lt;/li&gt;
&lt;li&gt;Be careful with strongly typing parameters. For the most part it&amp;#39;s a good thing to strongly type variables, but I&amp;#39;ve found a few cases where it is isn&amp;#39;t. I have several functions where I add PSNoteProperties to a strongly type object. If I then pipe the output to be used by another function whiich is also strongly typed the noteproperties are striped away leaving just the original object. The solution is to not strongly type the parameter.&lt;/li&gt;
&lt;li&gt;The position binder is supposed to be optional, however if I specify a parameterset this seems to be required in order to use positional.&lt;/li&gt;
&lt;li&gt;I wasn&amp;#39;t able to do anything more than simple pattern matching with &lt;strong&gt;FunctionsToExport &lt;/strong&gt;in the module manifest. This might be OK, but being able to explicitly list functions to export would be nice. What I ended up doing here is being very careful about adopting a standard prefix within a module.&lt;/li&gt;
&lt;li&gt;By default all functions within a module are exported (this means they are available for use), however aliases are not. I spent a day wrestling with this issue and posted &lt;a href="http://stackoverflow.com/questions/1978355/unable-to-create-a-powershell-alias-in-a-script-module" target="_blank"&gt;a StackOverFlow question&lt;/a&gt;. Although I agree aliases can sometime confuse things, not exporting alias by default I explicitly create within a module is counter-intuitive to the approach taken with functions. My thought is that if I didn&amp;#39;t want my aliases exported why would I create in my module? I&amp;#39;m sure this was a well-intentioned design decision, but it&amp;#39;s probably a little over thought.&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;/p&gt;&lt;/p&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=17412" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>The Black Art of PowerShell V2 Version Numbers</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/01/28/the-black-art-of-powershell-v2-version-numbers.aspx</link><pubDate>Thu, 28 Jan 2010 09:14:40 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:17343</guid><dc:creator>cmille19</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=17343</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/01/28/the-black-art-of-powershell-v2-version-numbers.aspx#comments</comments><description>&lt;div&gt;Last week while helping someone in the &lt;a href="http://sqlpsx.codeplex.com/Thread/View.aspx?ThreadId=81644" target="_blank"&gt;SQLPSX forums having an issue importing modules&lt;/a&gt; I suspected they had a CTP version of Powershell, but being the skeptical person I am I needed proof. My first thought was there must be a simple built-in command to return the Powershell version number. In fact there there is with &lt;strong&gt;$PSVersionTable. &lt;/strong&gt;This built-in variable was introduced in Powershell V2. If you run $PSVersionTable in Powershell V1 nothing will be returned. If you run $PSVersionTable on Powershell V2 you&amp;#39;ll get, a table of version information. &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;There&amp;#39;s one problem the version number information returned from $PSVersionTable will be different per OS platform and there isn&amp;#39;t single field that returns a consistent version number across platforms. For example on my x86 Vista the Powershell BuildVersion is 6.0.6002.18111. and on my x86 Windows 7 it is 6.1.7600.16385 yet both are RTM Powershell V2.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;For someone coming from a SQL Server background this is suprising . I&amp;#39;ve run SQL Server on x86, x64 and IA-64 platforms with various operating systems, however @@version returns one version number regardless of platform. Of course there are other pieces of data to show the H/W platform and OS available if needed, but in most cases I just want to see the base version number.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Armed with this information I tweeted a question on Friday, Jan 22nd -- &amp;quot;&lt;em&gt;How do you tell if somone has a CTP version of  Powershell&lt;/em&gt;?&amp;quot; Powershell MVP, &lt;a href="http://max-pit.spaces.live.com/" target="_blank"&gt;Max Trinidad&lt;/a&gt; quickly picked up on tweeter thread, tested a few things, &lt;a href="http://max-pit.spaces.live.com/blog/cns!A034D6A0DDC4E64E!918.entry" target="_blank"&gt;blogged&lt;/a&gt; and involved other MVPs. The result is &lt;a href="http://max-pit.spaces.live.com/blog/cns!A034D6A0DDC4E64E!918.entry" target="_blank"&gt;a blog post that helped me help someone else&lt;/a&gt;. Within a couple of days there were more blog posts on finding CTPs versions...&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;a href="http://powershell.com/cs/blogs/tobias/archive/2010/01/24/are-you-using-the-correct-powershell-version.aspx" target="_blank"&gt;Are you using the correct PowerShell version&lt;/a&gt; by &lt;a href="http://powershell.com/cs/members/Tobias/default.aspx" target="_blank"&gt;Tobias Weltner&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;&lt;a href="http://blogs.msdn.com/powershell/archive/2010/01/25/use-the-right-version-of-powershell.aspx" target="_blank"&gt;Use The Right Version of PowerShell&lt;/a&gt; from the &lt;a href="http://blogs.msdn.com/powershell/default.aspx" target="_blank"&gt;Powershell Team blog&lt;/a&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;As a result of this exercise I learned several things:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;h3&gt;&lt;strong&gt;The Powershell community and product team are awesome&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;OK, I already knew this, but how cool is it that you can tweet a question and have bunch people mobilize to help!&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;Powershell version numbering is wacked&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;Let&amp;#39;s fix this in Version 3. Please vote for my &lt;a href="https://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=527860" target="_blank"&gt;connection item&lt;/a&gt; to add a version property consistent across all platforms to $psversiontable&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;Tweeter moves faster than blogs. Blogs move faster than support articles&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;If I have a question that can easily be expressed in under 140 characters and isn&amp;#39;t too obscure I&amp;#39;ll use Tweeter. Usually I get some really good answers. There used to be a time when the first step to troubleshooting problems with Microsoft products was to search &lt;a href="http://support.microsoft.com/"&gt;http://support.microsoft.com&lt;/a&gt; or going back in the real olden days the TechNet CD&amp;#39;s. Today the idea of looking at a KB article is often an afterthought done when Google/Bing turn up nothing. It would seem even product teams teams would rather blog than initiate a knowledge article. Not that this is a bad thing, personally I&amp;#39;d rather have the information delivered faster in a blog post. Support articles are generated by customer&amp;#39;s calls. When several customers call about the same issue a KB article is published. So, by putting the information out in a blog this may reduce customer calls which then mean no KB article. One last thought on KB articles, not only are they slow to produce, but because they are purely text based they simply haven&amp;#39;t kept pace with how people like to see information . Some of the most helpful blog posts I&amp;#39;ve found for troubleshooting an issue include screen prints or maybe even a video. It is more and more often that I&amp;#39;ll find the answer to problem or setup question in some helpful person&amp;#39;s blog.&lt;/p&gt;
&lt;h3&gt;&lt;strong&gt;For some reason which I don&amp;#39;t fully understand the Powershell team can&amp;#39;t pull down the Powershell CTP download&lt;/strong&gt;&lt;/h3&gt;
&lt;p&gt;The problem with not pulling CTP releases is that people will mistakenly grab a CTP instead of a release version. This problem is compounded by search engines returning the Powershell Version 2 CTP download when searching for &amp;quot;Powershell Version 2 Download.&amp;quot; I don&amp;#39;t know if Powershell bloggers who included links to CTP downloads in posts prior to release contribute to the search engine problem or not, but to be safe my suggestion -- don&amp;#39;t include links to CTP releases in future posts for unreleased products. The CTP releases are generally pulled from download shortly after a product is released. I don&amp;#39;t know what is common practice as far as timing, but I do know I can&amp;#39;t find old CTP releases of SQL Server (or maybe I&amp;#39;m not looking hard enough). If you have an insight into CTP releases, please comment.&lt;/p&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=17343" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>SQL Saturday #32</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/01/23/sql-saturday-_2300_32.aspx</link><pubDate>Sun, 24 Jan 2010 01:59:57 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:17197</guid><dc:creator>cmille19</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=17197</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/01/23/sql-saturday-_2300_32.aspx#comments</comments><description>&lt;div&gt;I presented a one hour session at &lt;a href="http://www.sqlsaturday.com/eventhome.aspx" target="_blank"&gt;SQL Saturday #32&lt;/a&gt; in Tampa on &lt;a href="http://www.sqlsaturday.com/viewsession.aspx?sat=32&amp;amp;sessionid=882" target="_blank"&gt;Powershell ETL&lt;/a&gt;: &amp;quot;In this sesssion we will look at performing common data loading tasks with Powershell. A basic understanding of PowerShell is helpful, but not necessary. Specific topics covered include importing structured files, XML, WMI objects and ADO.NET data sources.&amp;quot;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;SQL Saturday&amp;#39;s and Code Camps usually host a Powershell track and Tampa SQL Saturday was no exception. &lt;a href="http://sqlvariant.com/wordpress/" target="_blank"&gt;Aaraon Nelson&lt;/a&gt; and &lt;a href="http://www.simple-talk.com/author/ron-dameron/" target="_blank"&gt;Ron Damron&lt;/a&gt; also presented complimentary Powershell sessions on &lt;a href="http://www.sqlsaturday.com/viewsession.aspx?sat=32&amp;amp;sessionid=895" target="_blank"&gt;Powershell for Data Professionals&lt;/a&gt; and &lt;a href="http://www.sqlsaturday.com/viewsession.aspx?sat=32&amp;amp;sessionid=895" target="_blank"&gt;Database Hardening via Powershell&lt;/a&gt; respectively. Between the three of use we had a half day of Powershell on Saturday!&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;My thanks to everyone in attendence. I hope to see many of you at our first &lt;a href="http://www.tampapowershell.com/" target="_blank"&gt;Tampa Powershell User Group&lt;/a&gt; meeting on March 11, 2010. Feel free to post questions and comments. The presentation and supporting materials for the &lt;strong&gt;Powershell ETL&lt;/strong&gt; session are available here:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt; &lt;/div&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=17197" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>Hello SMO (F#) World!</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/01/13/hello-smo-_2800_f_23002900_-world_2100_.aspx</link><pubDate>Thu, 14 Jan 2010 00:56:00 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:16934</guid><dc:creator>cmille19</dc:creator><slash:comments>6</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=16934</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/01/13/hello-smo-_2800_f_23002900_-world_2100_.aspx#comments</comments><description>&lt;div&gt;Reading &lt;a href="http://www.ctocorner.com/fsharp/book/" rel="nofollow" target="_blank"&gt;The F# Survival Guide&lt;/a&gt;&amp;nbsp;has motivated me to write my version of an F# &amp;quot;Hello World!&amp;quot; utility. What I mean by that is to write something simple that I&amp;#39;ve written in other programming languages as&amp;nbsp;a learning exercise. In my world of databases I use &lt;a href="http://msdn.microsoft.com/en-us/library/ms162169.aspx" rel="nofollow" target="_blank"&gt;SMO&lt;/a&gt; (&lt;strong&gt;pronounced smoh or S-M-O&lt;/strong&gt;). One of the easiest things I can do is&amp;nbsp; write some code to script out SQL Servers tables. &lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;I&amp;#39;m going to use the &lt;a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx" rel="nofollow" target="_blank"&gt;F#&lt;/a&gt; command-style interactive console, fsi.exe&amp;nbsp;that ships with F#. The only installation needed is F# and SMO version 10 that is included with SQL Server 2008 Management Studio. On my machine using the&amp;nbsp;Oct 2009 CTP version the path to fsi.exe is C:\Program Files\FSharp-1.9.7.8\bin. To run the interactive console&amp;nbsp;open a command windows and navigate to the bin directory and&amp;nbsp;run fsi.exe. Once in the interactive console you can either type or paste the F# code to run. Let&amp;#39;s take a look at the code and&amp;nbsp;then I&amp;#39;ll provide&amp;nbsp;a short&amp;nbsp;explaination:&lt;/div&gt;
&lt;div&gt;&amp;nbsp;&lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;&lt;font color="#80a0ff"&gt;#I @&amp;quot;C:\Program Files\Microsoft SQL Server\100\SDK\Assemblies\&amp;quot;;;&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;#r &amp;quot;Microsoft.SqlServer.Smo.dll&amp;quot;;;&lt;/font&gt;&lt;br /&gt;&lt;font color="#80a0ff"&gt;#r &amp;quot;Microsoft.SqlServer.ConnectionInfo.dll&amp;quot;;;&lt;/font&gt;&lt;br /&gt;open Microsoft.SqlServer.Management.Smo&lt;br /&gt;open Microsoft.SqlServer.Management.Common&lt;br /&gt;let svr = Server(@&lt;font color="#ffa0a0"&gt;&amp;quot;Z002\SQL2K8&amp;quot;&lt;/font&gt;)&lt;br /&gt;let db = svr.Databases.[&lt;font color="#ffa0a0"&gt;&amp;quot;pubs&amp;quot;&lt;/font&gt;]&lt;br /&gt;for t in db.Tables do&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;for s in t.Script() do&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;printfn &lt;font color="#ffa0a0"&gt;&amp;quot;%s&amp;quot;&lt;/font&gt;&amp;nbsp;s;;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Courier New"&gt;&lt;/font&gt;&amp;nbsp;&lt;/div&gt;
&lt;h3&gt;Notes&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;The first three lines are not comments, they are used to resovle the assembly path and reference the SMO assemblies. These lines are specific to the interactive console if you&amp;#39;re using Visual Studio you would add references as you would normally.&lt;/li&gt;
&lt;li&gt;F# is case sensitive&lt;/li&gt;
&lt;li&gt;Whitespace is important&lt;/li&gt;
&lt;li&gt;You use a dot before brackets to&amp;nbsp;access an element, which is&amp;nbsp;different than other languages&lt;/li&gt;
&lt;li&gt;Double semi-colons terminate a command in the interactive console&lt;/li&gt;
&lt;li&gt;The @ sign is used for &lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Times New Roman&amp;#39;, &amp;#39;serif&amp;#39;;FONT-SIZE:12pt;"&gt;&lt;font color="#000000"&gt;verbatim &lt;/font&gt;&lt;/span&gt;strings (here-strings) -- used&amp;nbsp;to escape special characters.&lt;/li&gt;
&lt;li&gt;The above example isn&amp;#39;t very F#-like which favors functions and &lt;span style="LINE-HEIGHT:115%;FONT-FAMILY:&amp;#39;Times New Roman&amp;#39;, &amp;#39;serif&amp;#39;;FONT-SIZE:12pt;"&gt;&lt;font color="#000000"&gt;recursion &lt;/font&gt;&lt;/span&gt;over imperative looping, but this just a simple example&lt;/li&gt;
&lt;li&gt;Although it may not look like it, F# is strongly typed. It uses type inference to determine type. You can explicitly type items&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;EDIT Jan 24, 2010:&lt;/strong&gt; &lt;a href="http://www.simple-talk.com/community/blogs/tony_davis/default.aspx" target="_blank"&gt;Tony Davis&lt;/a&gt; blogged about this post in his article &lt;a href="http://www.simple-talk.com/community/blogs/tony_davis/archive/2010/01/21/87875.aspx" target="_blank"&gt;Life at the F# end&lt;/a&gt;&amp;nbsp;providing a revised solution that is&amp;nbsp;more F#-like as follows:&lt;/p&gt;
&lt;p&gt;&lt;font face="monospace"&gt;db.Tables &lt;br /&gt;&amp;nbsp;&amp;nbsp; |&amp;gt; Seq.cast &lt;br /&gt;&amp;nbsp;&amp;nbsp; |&amp;gt; Seq.collect (fun (t:Table) -&amp;gt; t.Script() |&amp;gt; Seq.cast) &lt;br /&gt;&amp;nbsp;&amp;nbsp; |&amp;gt; Seq.iter (fun s -&amp;gt; printfn &amp;quot;%s&amp;quot; s);;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;You&amp;#39;ll need to read the article for an explanation of the F# code.&amp;nbsp;Tony also suggests F# as a common scripting language for both developers and administrators.&amp;nbsp;My thought on the subject is that Powershell&amp;nbsp;is the common scripting language for administrators, but perhaps F# may have a niche use case for administrators needing better scale--I would love to see more practical examples of F# administration scripts. Be sure to read&amp;nbsp;the comments section in which I&amp;nbsp;respond with my reasons for exploring F# out of a need&amp;nbsp;to achieve some concurrency missing&amp;nbsp; from Powershell. Oh, and I also appologize for making someones&amp;#39; teeth itch with my use of imperative looping in F# &lt;img style="VERTICAL-ALIGN:middle;" title="Open-mouthed" alt="Open-mouthed" src="http://shared.live.com/rzvDQW1qjIikH13dsbM42g/emoticons/smile_teeth.gif" /&gt;&lt;/p&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=16934" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/SMO/default.aspx">SMO</category><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/F_2300_/default.aspx">F#</category></item><item><title>Finding Invalid SQL Logins</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/01/12/finding-invalid-sql-logins.aspx</link><pubDate>Tue, 12 Jan 2010 08:14:26 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:16852</guid><dc:creator>cmille19</dc:creator><slash:comments>7</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=16852</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2010/01/12/finding-invalid-sql-logins.aspx#comments</comments><description>&lt;div&gt;As many of you know the system stored procedure &lt;a href="http://msdn.microsoft.com/en-us/library/ms181728.aspx" target="_blank"&gt;sp_validatelogins&lt;/a&gt; is used for finding invalid logins. Although sp_validatelogins is useful there&amp;#39;s one problem -- the output isn&amp;#39;t always accurate. You see when you add a a Windows account to SQL Server the &lt;a href="http://msdn.microsoft.com/en-us/library/aa379594(VS.85).aspx" target="_blank"&gt;SID&lt;/a&gt; as well as the domain (or computer name) slash account name are stored in master database, if the account is renamed in Active Directory or in the case of local users on the local system, the account stills retains access to SQL Server. How is this possible? That&amp;#39;s because the SID is unchanged and that is what SQL Server uses. When you run sp_validatelogins the account name is validated but not the SID and a valid but rename account is returned.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;So, what we need to do is make sp_validateLogins accurate by resolving the SID against Active Directory or the local system. As add bonus we should return the rename account name. Fortunately this is pretty easy with a little Powershell script. The following is a standalone excerpt from &lt;a href="http://sqlpsx.codeplex.com/" target="_blank"&gt;SQL Server PowerShell Extensions&lt;/a&gt;, edited to work with Microsoft&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/cc280450.aspx" target="_blank"&gt;sqlps&lt;/a&gt;:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;span style="color:#00008b;"&gt;function&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Get-InvalidLogins&lt;/span&gt;            &lt;br /&gt;&lt;span style="color:#000000;"&gt;{&lt;/span&gt;            &lt;br /&gt;    &lt;span style="color:#00008b;"&gt;param&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$ServerInstance&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            &lt;br /&gt;            &lt;br /&gt;    &lt;span style="color:#00008b;"&gt;foreach&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$r&lt;/span&gt; &lt;span style="color:#00008b;"&gt;in&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Invoke-SqlCmd&lt;/span&gt; &lt;span style="color:#000080;"&gt;-ServerInstance&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$ServerInstance&lt;/span&gt; &lt;span style="color:#000080;"&gt;-Database&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;master&amp;#39;&lt;/span&gt; &lt;span style="color:#000080;"&gt;-Query&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;sp_validatelogins&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            &lt;br /&gt;    &lt;span style="color:#000000;"&gt;{&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#ff4500;"&gt;$NTLogin&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$r&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#8b0000;"&gt;&amp;#39;NT Login&amp;#39;&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#ff4500;"&gt;$SID&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new-object&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;security.principal.securityidentifier&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$r&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;SID&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt;&lt;span style="color:#800080;"&gt;0&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#ff4500;"&gt;$newAccount&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$null&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#00008b;"&gt;trap&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$null&lt;/span&gt;&lt;span style="color:#000000;"&gt;;&lt;/span&gt; &lt;span style="color:#00008b;"&gt;continue&lt;/span&gt; &lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$newAccount&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$SID&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;translate&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#008080;"&gt;[system.security.principal.NTAccount]&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;            &lt;br /&gt;       &lt;span style="color:#00008b;"&gt;if&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$newAccount&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$null&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;             &lt;br /&gt;        &lt;span style="color:#ff4500;"&gt;$isOrphaned&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$true&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#ff4500;"&gt;$isRenamed&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$false&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            &lt;br /&gt;       &lt;span style="color:#00008b;"&gt;else&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#ff4500;"&gt;$isOrphaned&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$false&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#ff4500;"&gt;$isRenamed&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$true&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#00008b;"&gt;if&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$NTLogin&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-ne&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$newAccount&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#0000ff;"&gt;new-object&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;psobject&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#0000ff;"&gt;add-member&lt;/span&gt; &lt;span style="color:#000080;"&gt;-pass&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;NoteProperty&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;NTLogin&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$NTLogin&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#0000ff;"&gt;add-Member&lt;/span&gt; &lt;span style="color:#000080;"&gt;-pass&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;NoteProperty&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;TSID&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$SID&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#0000ff;"&gt;add-Member&lt;/span&gt; &lt;span style="color:#000080;"&gt;-pass&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;NoteProperty&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Server&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$ServerInstance&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#0000ff;"&gt;add-Member&lt;/span&gt; &lt;span style="color:#000080;"&gt;-pass&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;NoteProperty&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;IsOrphaned&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$isOrphaned&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#0000ff;"&gt;add-Member&lt;/span&gt; &lt;span style="color:#000080;"&gt;-pass&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;NoteProperty&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;IsRenamed&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$isRenamed&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#0000ff;"&gt;add-Member&lt;/span&gt; &lt;span style="color:#000080;"&gt;-pass&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;NoteProperty&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;NewNTAccount&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$newAccount&lt;/span&gt;            &lt;br /&gt;        &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            &lt;br /&gt;    &lt;span style="color:#000000;"&gt;}&lt;/span&gt;            &lt;br /&gt;            &lt;br /&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#006400;"&gt;#Get-InvalidLogins&lt;/span&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;To use the script simply copy and paste the function defintion into a sqlps session or alternatively you can add the function to your &lt;a href="http://msdn.microsoft.com/en-us/library/bb613488(VS.85).aspx" target="_blank"&gt;Windows Powershell profile&lt;/a&gt;.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Next simply call the function specifying a SQL Server instance:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;strong&gt;Get-InvalidLogins &amp;quot;Z002\SQL2K8&amp;quot;&lt;/strong&gt;&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt; &lt;/h3&gt;
&lt;h3&gt;Credits and History &lt;/h3&gt;
&lt;div&gt;The original idea for the code came from a blog post which uses a &lt;a href="http://blogs.msdn.com/lcris/archive/2005/09/26/474202.aspx" target="_blank"&gt;CLR solution&lt;/a&gt;.  In my pre-Powershell days (2006) I created this &lt;a href="http://www.sqlservercentral.com/scripts/Maintenance+and+Management/31782/" target="_blank"&gt;Perl script&lt;/a&gt;. &lt;/div&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=16852" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>PowerShell V2 Remoting</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2009/12/02/powershell-v2-remoting.aspx</link><pubDate>Wed, 02 Dec 2009 10:43:28 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:16061</guid><dc:creator>cmille19</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=16061</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2009/12/02/powershell-v2-remoting.aspx#comments</comments><description>&lt;div&gt;To use remoting you&amp;#39;ll need to install Powershell V2, unless you&amp;#39;re running Windows 2008 R2 or Windows 7, you&amp;#39;ll need to grab &lt;a href="http://support.microsoft.com/kb/968929" rel="nofollow" target="_blank"&gt;the latest version of the Windows Management Framework&lt;/a&gt;. &lt;a href="http://blogs.msdn.com/powershell/archive/2009/11/20/windows-powershell-and-the-windows-management-framework.aspx" rel="nofollow" target="_blank"&gt;The Framework includes PowerShell V2 + WINRM.&lt;/a&gt; What&amp;#39;s &lt;a href="http://msdn.microsoft.com/en-us/library/aa384426(VS.85).aspx" rel="nofollow" target="_blank"&gt;WINRM&lt;/a&gt;? It&amp;#39;s the service included in Windows 2008 and Vista that provides the remoting infrastructue used by PowerShell V2. The installation simply updates the binaries to Windows 2008 R2 and Windows 7 levels. The other thing to note is that Windows 2003 and XP are also now supported. Make sure you have V2 on both your server and client. From a security standpoint, remoting is disabled by default, requires an elevated administrator session to enable and once enabled only allows administrators to connect by default. If you&amp;#39;re interested in security I suggest you reading about internals of WINRM and the underlying protocol, WS-MAN. In my environment I use SCCM to push out Microsoft updates to servers and since PowerShell V2 is available as a &lt;a href="http://support.microsoft.com/kb/968929" rel="nofollow" target="_blank"&gt;Windows Update&lt;/a&gt;, SCCM can push out the PowerShell V2. &lt;em&gt;Note: Unlike PowerShell V1, V2 requests a reboot, so schedule accordingly. &lt;/em&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;In PowerShell V1 and V2 some cmdlets and .NET classess have always supported the concept of remote connections. For instance Get-WMIObject takes a computername parameter that does not rely on the new remoting infrastructure; when using the SMO Server class you can specify a remote SQL Server instance; and the same is true with ADO.NET. There are however cases where command-line programs don&amp;#39;t provide native support for remoting. In these situations the remoting capabilities of PowerShell V2 is going to be very useful.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Before setting up remoting, like you I searched the internet looking for blogs, article and documentation. Unfortunately I wasn&amp;#39;t that lucky when it comes to to finding PowerShell remoting topics. There are blog posts related to WS-MAN, WINRM, WINRS, the WS-MAN provider with different fringe use cases some which will lead you down a rabbit hole describing how to set up remoting in some obscure non-PowerShell, CTP or non-default manner. The only thing I want to do is enable plain vanilla remoting between domain attached computers.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;This is unfortunate because setting up remoting is, as we will soon see, very simple. What&amp;#39;s surprising is where I found the best documentation on remoting and PowerShell in general, my own PowerShell console using&lt;strong&gt; Get-Help.&lt;/strong&gt; This was one of those duh moments.  We know that PowerShell has a verb-noun naming convention and you can discover commands based on naming convention. You can then  use &lt;strong&gt;get-command &lt;/strong&gt;to see what you might be looking for and then use &lt;strong&gt;get-help&lt;/strong&gt; to view the documentation. But, what if you&amp;#39;re not sure of the command to execute and have a question on concepts? That&amp;#39;s when you should, take a look the about_* topics. For remoting specifically look at &lt;strong&gt;get-help about_remote_FAQ &lt;/strong&gt;(to see all about topics run &lt;strong&gt;get-help about_*&lt;/strong&gt;):&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Reading through &lt;strong&gt;about_remote_FAQ&lt;/strong&gt; you&amp;#39;ll see a heading entiled &lt;em&gt;&amp;quot;HOW TO CONFIGURE YOUR COMPUTER FOR REMOTING&amp;quot;&lt;/em&gt;, which is exactly what I was looking for.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;From the server computer, run (&lt;strong&gt;NOTE: You only have to run this command one time to enable remoting. It must be run from an elevated prompt):&lt;/strong&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;PS C:\&amp;gt; &lt;font color="#006633"&gt;&lt;b&gt;enable-psremoting&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;&lt;em&gt;You should see the following output&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;&lt;font face="monospace"&gt;
&lt;div&gt;&lt;br /&gt;WinRM Quick Configuration&lt;br /&gt;Running command &lt;font color="#ffa0a0"&gt;&amp;quot;Set-WSManQuickConfig&amp;quot;&lt;/font&gt; to enable this machine &lt;font color="#006633"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/font&gt; remote&lt;br /&gt;management through WinRM service.&lt;br /&gt; This includes:&lt;br /&gt;    &lt;font color="#ffa0a0"&gt;1&lt;/font&gt;. Starting &lt;font color="#006633"&gt;&lt;b&gt;or&lt;/b&gt;&lt;/font&gt; restarting (&lt;font color="#006633"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/font&gt; already started) the WinRM service&lt;br /&gt;    &lt;font color="#ffa0a0"&gt;2&lt;/font&gt;. Setting the WinRM service type to auto start&lt;br /&gt;    &lt;font color="#ffa0a0"&gt;3&lt;/font&gt;. Creating a listener to accept requests on any IP address&lt;br /&gt;    &lt;font color="#ffa0a0"&gt;4&lt;/font&gt;. Enabling firewall exception &lt;font color="#006633"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/font&gt; &lt;font color="#006633"&gt;&lt;b&gt;WS-Management&lt;/b&gt;&lt;/font&gt; traffic (&lt;font color="#006633"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/font&gt; http only).&lt;br /&gt;&lt;br /&gt;&lt;font color="#006633"&gt;&lt;b&gt;Do&lt;/b&gt;&lt;/font&gt; you want to &lt;font color="#006633"&gt;&lt;b&gt;continue&lt;/b&gt;&lt;/font&gt;?&lt;br /&gt;&lt;font color="#60ff60"&gt;&lt;b&gt;&lt;img src="http://www.sqlservercentral.com/blogs/emoticons/emotion-21.gif" alt="Yes" /&gt;&lt;/b&gt;&lt;/font&gt; Yes  &lt;font color="#60ff60"&gt;&lt;b&gt;&lt;img src="http://www.sqlservercentral.com/blogs/emoticons/emotion-13.gif" alt="Angel" /&gt;&lt;/b&gt;&lt;/font&gt; Yes to All  &lt;font color="#60ff60"&gt;&lt;b&gt;&lt;img src="http://www.sqlservercentral.com/blogs/emoticons/emotion-45.gif" alt="No" /&gt;&lt;/b&gt;&lt;/font&gt; No  &lt;font color="#60ff60"&gt;&lt;b&gt;[L]&lt;/b&gt;&lt;/font&gt; No to All  &lt;font color="#60ff60"&gt;&lt;b&gt;&lt;img src="http://www.sqlservercentral.com/blogs/emoticons/emotion-56.gif" alt="Sleep" /&gt;&lt;/b&gt;&lt;/font&gt; Suspend  [?] Help&lt;br /&gt;(&lt;font color="#006633"&gt;&lt;b&gt;default&lt;/b&gt;&lt;/font&gt; &lt;font color="#006633"&gt;&lt;b&gt;is&lt;/b&gt;&lt;/font&gt; &lt;font color="#ffa0a0"&gt;&amp;quot;Y&amp;quot;&lt;/font&gt;):Y&lt;br /&gt;WinRM already &lt;font color="#006633"&gt;&lt;b&gt;is&lt;/b&gt;&lt;/font&gt; set up to receive requests on this machine.&lt;br /&gt;WinRM has been updated &lt;font color="#006633"&gt;&lt;b&gt;for&lt;/b&gt;&lt;/font&gt; remote management.&lt;br /&gt;Created a WinRM listener on &lt;a href="http://*/"&gt;HTTP://*&lt;/a&gt; to accept &lt;font color="#006633"&gt;&lt;b&gt;WS-Man&lt;/b&gt;&lt;/font&gt; requests to any IP on thi&lt;br /&gt;s machine.&lt;/div&gt;
&lt;div&gt;&lt;br /&gt; &lt;/div&gt;&lt;/font&gt;
&lt;div&gt;&lt;font face="monospace"&gt;&lt;em&gt;Then execute the following command to test remoting (this will connect to the local host):&lt;br /&gt;&lt;/em&gt;PS C:\&amp;gt; &lt;font color="#006633"&gt;&lt;b&gt;new-pssession&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;&lt;em&gt;You should see the following, showing an open local connection:&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;&lt;br /&gt; Id Name            ComputerName    State    ConfigurationName     Availability&lt;br /&gt; -- ----            ------------    -----    -----------------     ------------&lt;br /&gt;  &lt;font color="#ffa0a0"&gt;1&lt;/font&gt; Session1        localhost       Opened   Microsoft.PowerShell     Available&lt;br /&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;Having completed the server-side setup, next take a look at &lt;strong&gt;get-help about_remote&lt;/strong&gt;. This document will walk you through the three main remoting scenarios of interactive session, remote command, commands in a session:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;em&gt;&lt;strong&gt;From the client machine (i.e. your workstation), start an interactive session with the server, in this case Z002  is the remote server.&lt;/strong&gt;&lt;/em&gt;&lt;/div&gt;
&lt;div&gt;&lt;strong&gt; &lt;/strong&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;PS C:\&amp;gt; &lt;font color="#006633"&gt;&lt;b&gt;enter-pssession&lt;/b&gt;&lt;/font&gt; Z002&lt;br /&gt;&lt;font color="#60ff60"&gt;&lt;b&gt;[Z002]&lt;/b&gt;&lt;/font&gt;: PS C:\&amp;gt; &lt;font color="#40ffff"&gt;$env:computername&lt;/font&gt;&lt;br /&gt;Z002&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;&lt;strong&gt;When finish close the remote connection:&lt;/strong&gt;&lt;br /&gt;&lt;font color="#60ff60"&gt;&lt;b&gt;[Z002]&lt;/b&gt;&lt;/font&gt;: PS C:\&amp;gt; &lt;font color="#006633"&gt;&lt;b&gt;Exit-PSSession&lt;/b&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;em&gt;&lt;strong&gt;To execute a non-interactive remote command use the invoke-command cmdlet, specifying a remote server:&lt;/strong&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;PS C:\&amp;gt; &lt;font color="#006633"&gt;&lt;b&gt;invoke-command&lt;/b&gt;&lt;/font&gt; -computer Z002 {&lt;font color="#40ffff"&gt;$env:computername&lt;/font&gt;}&lt;br /&gt;Z002&lt;br /&gt;&lt;br /&gt;&lt;font color="#000000"&gt;&lt;strong&gt;The final remoting method is to create a session. This is useful when you want to execute a of series of commands. Create a session object and specify the object ($s) as a parameter to invoke-command. If you have additional commands keep specifying $s as parameter:&lt;/strong&gt;&lt;/font&gt;&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="monospace"&gt;&lt;font color="#40ffff"&gt;$s&lt;/font&gt; = &lt;font color="#006633"&gt;&lt;b&gt;new-pssession&lt;/b&gt;&lt;/font&gt; Z002&lt;br /&gt;PS C:\&amp;gt; &lt;font color="#006633"&gt;&lt;b&gt;invoke-command&lt;/b&gt;&lt;/font&gt; &lt;font color="#40ffff"&gt;$s&lt;/font&gt; {&lt;font color="#40ffff"&gt;$env:computername&lt;/font&gt;}&lt;br /&gt;Z002&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;Remoting between two domain attached computers is pretty easy. Although the same help topics you&amp;#39;ll find in get-help are available online, I&amp;#39;m purposely not linking to them. The help topics available within the PowerShell console are pretty good, so, put down Google/Bing and start using Get-Help!&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=16061" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>Tampa Code Camp 2009</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2009/11/07/tampa-code-camp-2009.aspx</link><pubDate>Sun, 08 Nov 2009 01:21:32 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:15554</guid><dc:creator>cmille19</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=15554</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2009/11/07/tampa-code-camp-2009.aspx#comments</comments><description>&lt;div&gt;I presented a 1 hr session at &lt;a href="http://www.tampacodecamp.com/" target="_blank"&gt;Tampa Code Camp 2009&lt;/a&gt;: &lt;strong&gt;PowerShell for Developers&lt;/strong&gt; In this sesssion we will look at the a main use cases for developer usage of PowerShell. An overview of the PowerShell development model will be provided. Specific topics covered include: ETL, Testing, deployment automation, and management API.&lt;br /&gt; &lt;br /&gt;My thanks to everyone in attendence. Feel free to post questions and comments. The presentation and supporting materials are available here:&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;&lt;/div&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=15554" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>Stored Procedure Call Tree</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2009/11/01/stored-procedure-call-tree.aspx</link><pubDate>Mon, 02 Nov 2009 04:13:44 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:15410</guid><dc:creator>cmille19</dc:creator><slash:comments>1</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=15410</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2009/11/01/stored-procedure-call-tree.aspx#comments</comments><description>&lt;p&gt;I was reading a post by &lt;a href="http://sqlblog.com/blogs/linchi_shea/default.aspx" target="_blank"&gt;Linchi Shea&lt;/a&gt; in which he demonstrates a Perl script to &lt;a href="http://sqlblog.com/blogs/linchi_shea/archive/2009/10/23/find-the-complete-call-tree-for-a-stored-procedure.aspx" target="_blank"&gt;Find the complete call tree for a stored procedure&lt;/a&gt; and thought, how would I do this in PowerShell?&lt;/p&gt;
&lt;p&gt;Before we dissect a PowerShell approach, let’s look at a basic Perl approach. In Perl you typically find a command-line tool that produces the output you want albeit not in a usable format (Sure, sometimes you might get lucky and find a Perl module that does what you want, however when I used Perl I was never that lucky). This may involve several command lines tools. You’ll then parse the output of the tool and perhaps even use the output as input to other command-line tools. This is one of the strengths of a scripting language, you can quickly glue together tools to make a new tool--The scripter is a tool smith. &lt;/p&gt;
&lt;p&gt;The Perl solution to getting a stored procedure call tree involves executing osql.exe and using some regular expressions to parse the output of sp_helptext, looking for EXECUTE statements. When I wrote Perl I would do much the same thing. As an example when I needed to &lt;a href="http://www.sqlservercentral.com/scripts/Miscellaneous/31745/" target="_blank"&gt;report the share and NTFS permissions&lt;/a&gt; using Perl for all SQL Servers, I would execute rmtshare.exe parse the output which was then used as input to fileacl.exe and the output was then parsed.&lt;/p&gt;
&lt;p&gt;We could do much the same thing in PowerShell, execute osql.exe and parse the output, however in the vast majority of cases if you’re parsing something in PowerShell you’re doing it the hard way. This is because PowerShell works with .NET, WMI and COM and you’ll typically find a .NET/WMI class or COM interface to do exactly what you want to do. Of course the hard part is knowing which class to use, if you’re not sure search and then ask. If you’re unable to find the answer yourself, both &lt;a href="http://serverfault.com/" target="_blank"&gt;ServerFault&lt;/a&gt; and &lt;a href="http://stackoverflow.com/" target="_blank"&gt;StackOverflow&lt;/a&gt; are good places to post these types of questions.&lt;/p&gt;
&lt;p&gt;There is a nice set of .NET classes for parsing T-SQL code included with Visual Studio Team System 2008 Database Edition (VSDB) in the classes &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.data.schema.scriptdom.aspx" target="_blank"&gt;Microsoft.Data.Schema.ScriptDom&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/microsoft.data.schema.scriptdom.sql.aspx" target="_blank"&gt;Microsoft.Data.Schema.ScriptDom.Sql&lt;/a&gt;. I’ve &lt;a href="http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!296.entry" target="_blank"&gt;blogged about these classes before&lt;/a&gt; and even use them in &lt;a href="http://sqlpsx.codeplex.com/" target="_blank"&gt;SQL Server PowerShell Extensions&lt;/a&gt; (SQLPSX). At this point, you’re probably thinking I don’t have VSDB, well that’s OK, because &lt;a href="http://blogs.msdn.com/gertd/archive/2008/08/22/redist.aspx" target="_blank"&gt;the assemblies are redistributable&lt;/a&gt; I’ve included them with SQLPSX and the accompanying download to this post. There’s only one problem with the VSDB assemblies, they are implemented as interfaces. Let me explain the issue.&lt;/p&gt;
&lt;p&gt;When writing PowerShell scripts you will often work with .NET classes. You’ll create an object from a .NET class and start working directly with it’s properties and methods. &lt;a href="http://msdn.microsoft.com/en-us/library/cc285859.aspx" target="_blank"&gt;SQL Server Management Objects or SMO&lt;/a&gt; is great example of this. In one line of PowerShell code you have instant access to hundreds of properties and methods for a SQL Server object:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#ff4500;"&gt;$srv&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new-object&lt;/span&gt; &lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#8b0000;"&gt;&amp;quot;Microsoft.SqlServer.Management.Smo.Server&amp;quot;&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; Z002\SQL2K8&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;As you can see with the example above its very simple to start working with a .NET class. There is however, one notable exception when dealing with interfaces.  This is kind of fringe use case, in most instances you won’t have to deal with interfaces in PowerShell. The best way I can describe an interface is a fancy abstraction thing developers use when creating classes. Only interfaces aren’t real classes and in order to use an interface you have to implement a class. The important thing to note, as a scripter an interface just means we need to create a class to use it and this requires a .NET language other than PowerShell. Fortunately PowerShell V2 through the &lt;strong&gt;add-type&lt;/strong&gt; cmdlet provides a way for us to do this within PowerShell.&lt;/p&gt;
&lt;p&gt;Using &lt;strong&gt;add-type&lt;/strong&gt; we can create a dynamic type in  .NET languages like C#. This means you can write C# within PowerShell. The first time I saw this I thought,”And why would I want to do that?” And then I remembered the problem with interfaces and in a way this functionality goes back to the main purpose of scripting, to glue together tools to create a new tool. Only in this case the tool is a snippet of C# code! So, I created a script called &lt;a href="http://poshcode.org/1445" target="_blank"&gt;SQLParser&lt;/a&gt; that implements the Microsoft.Data.Schema.ScriptDom and Microsoft.Data.Schema.ScriptDom.Sql interfaces with a basic C# class. &lt;/p&gt;
&lt;p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;To use &lt;strong&gt;SQLParser&lt;/strong&gt;, source the script file and create a &lt;strong&gt;SQLParser&lt;/strong&gt; object by specifying the SQL version, whether quoted identifiers are used and some valid T-SQL:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;./SQLParser.ps1&lt;/span&gt;&lt;/pre&gt;&lt;pre&gt;&lt;span style="color:#ff4500;"&gt;$sqlparser&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;new-object&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;SQLParser&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Sql100&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$false&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt;&lt;span style="color:#8b0000;"&gt;&amp;quot;Select * from dbo.authors&amp;quot;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;The SQLParser class returns a fragment, which then is made up of batches and finally statements. We can iterate through the statements looking for a particular statement type. Having accomplished the hard part of finding and implementing a .NET class for T-SQL parsing, I then created a PowerShell script called &lt;a href="http://poshcode.org/1446" target="_blank"&gt;Get-ProcedureCallTree.ps1&lt;/a&gt; to return a stored procedure call tree:&lt;/p&gt;
&lt;p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;If you run the script with the following parameters for HumanResources.uspUpdateEmplyeeHireInfo in the AdventureWorks database replacing Z002\SQL2K8 with your server name, you’ll should see the following output:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#0000ff;"&gt;.\Get-ProcedureCallTree.ps1&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;uspUpdateEmployeeHireInfo&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;Z002\SQL2K8&amp;quot;&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;AdventureWorks&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;HumanResources&lt;/span&gt;            
            
&lt;span style="color:#0000ff;"&gt;Server&lt;/span&gt;    &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Z002\SQL2K8&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Database&lt;/span&gt;  &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;AdventureWorks&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Schema&lt;/span&gt;    &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;dbo&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Procedure&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;uspLogError&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Source&lt;/span&gt;    &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Z002\SQL2K8.AdventureWorks.HumanResources.uspUpdateEmployeeHireInfo&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Target&lt;/span&gt;    &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Z002\SQL2K8.AdventureWorks.dbo.uspLogError&lt;/span&gt;            
            
&lt;span style="color:#0000ff;"&gt;Server&lt;/span&gt;    &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Z002\SQL2K8&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Database&lt;/span&gt;  &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;AdventureWorks&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Schema&lt;/span&gt;    &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;dbo&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Procedure&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;uspPrintError&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Source&lt;/span&gt;    &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Z002\SQL2K8.AdventureWorks.dbo.uspLogError&lt;/span&gt;            
&lt;span style="color:#0000ff;"&gt;Target&lt;/span&gt;    &lt;span style="color:#8a2be2;"&gt;:&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Z002\SQL2K8.AdventureWorks.dbo.uspPrintError&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Not bad, but what I really want is to visualize the call tree. One method that works well for dependency maps is a script called &lt;strong&gt;Show-NetMap&lt;/strong&gt; created by &lt;a href="http://dougfinke.com/blog/" target="_blank"&gt;Doug Finke&lt;/a&gt; featured in his blog post &lt;a href="http://dougfinke.com/blog/index.php/2009/01/26/powershell-visualize-the-peanut-butter-recall-data" target="_blank"&gt;PowerShell, Visualize the Peanut Butter Recall Data.&lt;/a&gt;. I’ve &lt;a href="http://chadwickmiller.spaces.live.com/blog/cns!EA42395138308430!305.entry" target="_blank"&gt;previously blogged about this script&lt;/a&gt; using it to create a complete database dependency map. To use &lt;strong&gt;Show-NetMap&lt;/strong&gt;, source the script and pipe the source and target properties to &lt;strong&gt;Show-NetMap&lt;/strong&gt;:&lt;/p&gt;
&lt;p&gt;&lt;pre&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;.\Show-NetMap.ps1&lt;/span&gt;            
            
&lt;span style="color:#0000ff;"&gt;./Get-ProcedureCallTree.ps1&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;uspUpdateEmployeeHireInfo&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;Z002\SQL2K8&amp;quot;&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;AdventureWorks&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;HumanResources&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; `&lt;/pre&gt;&lt;pre&gt;&lt;span style="color:#0000ff;"&gt;Select&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Source&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt;&lt;span style="color:#8a2be2;"&gt;Target |&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Show-NetMap&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;F&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;&lt;a href="https://ddi59g.blu.livefilestore.com/y1m8_9bL_GlsflgjwWfIr9bWIq8GINikoNSSyuALqDsXryQYpzg6KolPGoEjw8jhzAfBOtH-riOFwkHokVztyx0G1aw2TbmC99raT70nb7jvl7quohmMmoL3T8J_DUwUv7mc6b3PsGVd7qQ3SNZWVszqw/ProcedureTree[2].jpg" rel="WLPP"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="ProcedureTree" border="0" alt="ProcedureTree" src="https://ddi59g.blu.livefilestore.com/y1mA-XQe7XbPUMYcOO_rLK1SdiVc4r5UDCem0cIVvLO5RTSb_xT1wDX7eGyKCFzmF2OUwBr4Ws6hO4baS09vm9FC_iiBRTdOa4nlynnwQGCzKY33xET_JvEraYbTwsnZRAz9gw13kwjpOcOREw4LwOHCA/ProcedureTree_thumb.jpg" width="244" height="91" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;That’s better! The scripts and assemblies demonstrated in this post are available here:&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=15410" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item><item><title>Operations Manager Shell</title><link>http://www.sqlservercentral.com/blogs/chadmiller/archive/2009/10/21/operations-manager-shell.aspx</link><pubDate>Wed, 21 Oct 2009 07:00:25 GMT</pubDate><guid isPermaLink="false">70975365-724d-4ce8-8d1c-45c963ab81ff:15092</guid><dc:creator>cmille19</dc:creator><slash:comments>0</slash:comments><wfw:commentRss xmlns:wfw="http://wellformedweb.org/CommentAPI/">http://www.sqlservercentral.com/blogs/chadmiller/rsscomments.aspx?PostID=15092</wfw:commentRss><comments>http://www.sqlservercentral.com/blogs/chadmiller/archive/2009/10/21/operations-manager-shell.aspx#comments</comments><description>&lt;div&gt;I&amp;#39;ve started using &lt;a href="http://www.microsoft.com/systemcenter/operationsmanager/en/us/default.aspx"&gt;SCOM 2007 R2&lt;/a&gt;, which has given me a chance to try out the &lt;a href="http://technet.microsoft.com/en-us/library/cc974484.aspx" target="_blank"&gt;Operations Manager Shell&lt;/a&gt;. The Ops Mgr Shell is a customized PowerShell initialized through a console file and startup script. The important thing to note is that it&amp;#39;s still regular PowerShell.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;What&amp;#39;s interesting about the Ops Mgr shell is the use of  both a provider and cmdlets. You can navigate groups and objects like a file system drive plus there are some nicely thought out cmdlets that can act within the current context of objects returned by the provider through pipeline input.  As someone coming from SQL Server PowerShell I couldn&amp;#39;t help but think this is how the SQL Server Powershell host should work i.e. cmdlets integrated with provider. Although many of the Ops Mgr cmdlets allow you to specify paths and objects as parameters for their cmdlets, I found it much easier to use the provider in conjunction with cmdlets--navigating to a group or object and then executing cmdlets to get or change properties.&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;div&gt;I&amp;#39;m more of a SCOM user than a SCOM administrator, so my use cases are simple and have nothing to do with administering SCOM. The only things I need to do is get a list of alerts for a particular group or alert and put groups or machines in maintenance mode to avoid alerts during planned maintenance. Here are some scripts I&amp;#39;ve used:&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#0000ff;"&gt;&lt;/span&gt; &lt;/div&gt;
&lt;div&gt;&lt;span style="color:#0000ff;"&gt;#Navigate to the SQL Server computer group&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#0000ff;"&gt;PS&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Monitoring:\sunfish1\Microsoft.SQLServer.ComputerGroup&lt;/span&gt;            &lt;br /&gt;&lt;/div&gt;
&lt;div&gt;#Get all unresolved alerts for the current group            &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;get-alert&lt;/span&gt; &lt;span style="color:#000080;"&gt;-criteria&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;ResolutionState = 0&amp;quot;&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Select&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Name&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Description&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;MonitoringObjectPath&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;MonitoringObjectName&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;TimeRaised&lt;/span&gt;            &lt;br /&gt;            &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;#Get alerts for where the alert name is logical disk frag and export results to CSV file&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#0000ff;"&gt;get-alert&lt;/span&gt; &lt;span style="color:#000080;"&gt;-criteria&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;Name like &amp;#39;Logical Disk Frag%&amp;#39;&amp;quot;&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Select&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Name&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Description&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;MonitoringObjectPath&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;,&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;MonitoringObjectName&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;export-csv&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;c:\users\u00\bin\DiskFrag.csv&lt;/span&gt; &lt;span style="color:#000080;"&gt;-noTypeInfo&lt;/span&gt;            &lt;br /&gt;            &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;#Put an entire group in maintenance mode for one hour&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#0000ff;"&gt;get-monitoringobject&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;New-MaintenanceWindow&lt;/span&gt; &lt;span style="color:#000080;"&gt;-startTime:&lt;/span&gt;&lt;span style="color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;get-date&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#000080;"&gt;-endTime:&lt;/span&gt;&lt;span style="color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;get-date&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;AddHours&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;1&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#000080;"&gt;-comment:&lt;/span&gt;&lt;span style="color:#8b0000;"&gt;&amp;quot;Testing PowerShell script&amp;quot;&lt;/span&gt;            &lt;br /&gt;&lt;/div&gt;
&lt;div&gt;#Put the Z002 computer in maintenance mode for one hour            &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;get-monitoringobject&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;where&lt;/span&gt; &lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;Name&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;-eq&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;#39;Z002.acme.com&amp;#39;&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;New-MaintenanceWindow&lt;/span&gt; &lt;span style="color:#000080;"&gt;-startTime:&lt;/span&gt;&lt;span style="color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;get-date&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#000080;"&gt;-endTime:&lt;/span&gt;&lt;span style="color:#000000;"&gt;$(&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#0000ff;"&gt;get-date&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;AddHours&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#800080;"&gt;1&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#000080;"&gt;-comment:&lt;/span&gt;&lt;span style="color:#8b0000;"&gt;&amp;quot;Testing PowerShell script&amp;quot;&lt;/span&gt;            &lt;br /&gt;            &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;#Note as a DBA two other groups you should look at:&lt;/span&gt;&lt;/div&gt;
&lt;div&gt;&lt;span style="color:#0000ff;"&gt;Microsoft.SQLServer.InstanceGroup&lt;/span&gt;            &lt;br /&gt;&lt;span style="color:#0000ff;"&gt;Microsoft.Windows.Clusters&lt;/span&gt;&lt;/div&gt;
&lt;div&gt; &lt;/div&gt;
&lt;h3&gt;A few tips&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;I find myself using the alert script just to export what I&amp;#39;m seeing in my Operations Console (GUI) to a CSV file. I&amp;#39;ll then send the simple PowerShell generated CSV reports to my team to address. If you know of an easier way to do this through the GUI, let me know. &lt;/li&gt;
&lt;li&gt;The maintenance mode scripts are not as useful, it&amp;#39;s easier to use the GUI, right-click, and select maintenance mode. Even multiple computers can be selected. I suppose if I had a regularly scheduled maintenance, I would find more uses for a scripted maintenance window solution.&lt;/li&gt;
&lt;li&gt;It is surprising what SCOM finds, the most common warning condition I&amp;#39;ve seen include databases with autoclose or autoshrink on. In an active environment with thousands of databases a few inherited databases from SQL Express installation are bound to exist with either autoclose or autoshrink on. Once identified these warning are easy to fix.&lt;/li&gt;
&lt;li&gt;One other interesting warning is logical disk defragmentation. I had do a little research about this warning and &lt;a href="http://serverfault.com/questions/74196/how-is-win32defraganalysis-filepercentfragmentation-calculated" target="_blank"&gt;posted a question to ServerFault&lt;/a&gt;. I won&amp;#39;t repost here; see the ServerFault Q&amp;amp;A for detailed explanation. As part of the question I created a short script to retrieve logical fragmentation through WMI and PowerShell:&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt; &lt;span style="color:#ff4500;"&gt;$vols&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;Get-WmiObject&lt;/span&gt; &lt;span style="color:#000080;"&gt;-computername&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;Z002&amp;quot;&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;Win32_Volume&lt;/span&gt; &lt;span style="color:#000080;"&gt;-filter&lt;/span&gt; &lt;span style="color:#8b0000;"&gt;&amp;quot;DriveType=3&amp;quot;&lt;/span&gt;            &lt;br /&gt;&lt;span style="color:#ff4500;"&gt;$defragInfo&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;=&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$vols&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;%&lt;/span&gt;&lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;DefragAnalysis&lt;/span&gt;&lt;span style="color:#000000;"&gt;(&lt;/span&gt;&lt;span style="color:#000000;"&gt;)&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;add-member&lt;/span&gt; &lt;span style="color:#000080;"&gt;-membertype&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;noteproperty&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;vname&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;name&lt;/span&gt; &lt;span style="color:#000080;"&gt;-passThru&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt;            &lt;br /&gt;&lt;span style="color:#ff4500;"&gt;$defragInfo&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;%&lt;/span&gt;&lt;span style="color:#000000;"&gt;{&lt;/span&gt;&lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;DefragAnalysis&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;add-member&lt;/span&gt; &lt;span style="color:#000080;"&gt;-membertype&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;noteproperty&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;DefragRecommended&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;DefragRecommended&lt;/span&gt; &lt;span style="color:#000080;"&gt;-passThru&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;add-member&lt;/span&gt; &lt;span style="color:#000080;"&gt;-membertype&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;noteproperty&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;vname&lt;/span&gt; &lt;span style="color:#ff4500;"&gt;$_&lt;/span&gt;&lt;span style="color:#a9a9a9;"&gt;.&lt;/span&gt;&lt;span style="color:#000000;"&gt;vname&lt;/span&gt; &lt;span style="color:#000080;"&gt;-passThru&lt;/span&gt;&lt;span style="color:#000000;"&gt;}&lt;/span&gt; &lt;span style="color:#a9a9a9;"&gt;|&lt;/span&gt; &lt;span style="color:#0000ff;"&gt;out-file&lt;/span&gt; &lt;span style="color:#8a2be2;"&gt;./tmp.txt&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;The script can be executed remotely, retrieves the logical disk fragmentation for computer, Z002 and sends the output to a text file. The fragmentation numbers produced by the script seem to match what Ops Mgr produces. This illustrates one of the cool things about PowerShell, with a little work you can use scripting to better understand how management tools like SCOM work!&lt;/div&gt;&lt;img src="http://www.sqlservercentral.com/blogs/aggbug.aspx?PostID=15092" width="1" height="1"&gt;</description><category domain="http://www.sqlservercentral.com/blogs/chadmiller/archive/tags/PowerShell/default.aspx">PowerShell</category></item></channel></rss>