<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx</link><description>Summary: Use Windows PowerShell to collect server data and automatically store that information in a Microsoft SQL Server. 
 
 Hey, Scripting Guy! How is Windows PowerShell usage by database professionals different from the way that other IT Pros use</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx#3552374</link><pubDate>Wed, 13 Feb 2013 23:56:42 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3552374</guid><dc:creator>wheresjeannine</dc:creator><description>&lt;p&gt;I want to run my PS script that dumps all details of all WEBs, Lists, Libraries, Folders, Documents, ITems and Attachments from SharePoint and send that output to a SQL Server database table. Q: Can do? Q: Am I dreaming too big? Imquiring minds need to know jeannine.menger@recommind &amp;nbsp; &amp;nbsp;(dot) &amp;nbsp; &amp;nbsp;com&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3552374" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx#3550894</link><pubDate>Wed, 06 Feb 2013 19:47:30 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3550894</guid><dc:creator>mbourgon</dc:creator><description>&lt;p&gt;Answering my own question, sorta - asked on Stackoverflow and Chad Miller (the guy who wrote the above code) answered. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Two ways to do it, provided you ran something like this:&lt;/p&gt;
&lt;p&gt;$dt = invoke-sqlcmd2 -serverinstance $_.server -query &amp;quot;exec master.dbo.sp_who&amp;quot; -As &amp;#39;Datatable&amp;#39; &lt;/p&gt;
&lt;p&gt;and you want to add the Servername (yes, sp_who returns the server name, but I wanted an SP everyone had)&lt;/p&gt;
&lt;p&gt;Either:&lt;/p&gt;
&lt;p&gt;$Col = &amp;nbsp;new-object Data.DataColumn&lt;/p&gt;
&lt;p&gt;$Col.ColumnName = &amp;quot;ServerName&amp;quot;&lt;/p&gt;
&lt;p&gt;$dt.Columns.Add($col)&lt;/p&gt;
&lt;p&gt;$dt | %{$_.ServerName = $server}&lt;/p&gt;
&lt;p&gt;Or (abbreviated version):&lt;/p&gt;
&lt;p&gt;$dt.Columns.Add(&amp;quot;ServerName&amp;quot;)&lt;/p&gt;
&lt;p&gt;$dt | %{$_.ServerName = $server} &amp;nbsp;#in my main foreach I say $server = $_.server&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3550894" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx#3550539</link><pubDate>Tue, 05 Feb 2013 20:30:38 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3550539</guid><dc:creator>mbourgon</dc:creator><description>&lt;p&gt;(grr - stupid post button)&lt;/p&gt;
&lt;p&gt;JV - sorry, how do you do that in powershell? &amp;nbsp;(should have been more clear). &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Say I did this:&lt;/p&gt;
&lt;p&gt;$dt = invoke-sqlcmd2 -serverinstance myservername -query &amp;quot;exec sp_who&amp;quot; -As &amp;#39;Datatable&amp;#39; &lt;/p&gt;
&lt;p&gt;I now have a datatable. &amp;nbsp;I want to copy the details of $dt into a new DataTable (so that I can add the ServerName field), then write using write-datatable. &amp;nbsp;But since I&amp;#39;m multithreading it, I need to do this within the PS script; I can&amp;#39;t use t-sql or interim tables for that part.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3550539" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx#3550537</link><pubDate>Tue, 05 Feb 2013 20:30:02 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3550537</guid><dc:creator>mbourgon</dc:creator><description>&lt;p&gt;JV - sorry, how do you do that in powershell? &amp;nbsp;(should have been more clear). &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Say I did this:&lt;/p&gt;
&lt;p&gt;$dt = invoke-sqlcmd2 -serverinstance myservername -query &amp;quot;exec sp_who&amp;quot; -As &amp;#39;Datatable&amp;#39; &lt;/p&gt;
&lt;p&gt;I now have a datatable. &amp;nbsp;I want to copy the details of $dt into a new DataTable (so that I can add the ServerName field), then write using write-datatable. &amp;nbsp;But since I&amp;#39;m multithreading it, I need to do this within the PS script; I can&amp;#39;t use &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3550537" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx#3550487</link><pubDate>Tue, 05 Feb 2013 16:58:59 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3550487</guid><dc:creator>JV</dc:creator><description>&lt;p&gt;@mbourgon&lt;/p&gt;
&lt;p&gt;insert into datatablea2 select &amp;#39;myserver as ServreName, * from datatable1&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3550487" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx#3550480</link><pubDate>Tue, 05 Feb 2013 16:22:07 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3550480</guid><dc:creator>mbourgon</dc:creator><description>&lt;p&gt;JV - cool! &amp;nbsp;Now I&amp;#39;m getting somewhere. &amp;nbsp;Is there an easy way to say &amp;quot;copy field + datatable1 into datatable2&amp;quot;? &amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m trying to take the results of an SP and add the servername to it, before writing to a table. All help appreciated!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3550480" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx#3550340</link><pubDate>Mon, 04 Feb 2013 22:44:56 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3550340</guid><dc:creator>JV</dc:creator><description>&lt;p&gt;@mbourgon&lt;/p&gt;
&lt;p&gt;You can&amp;#39;t a a column to the beginning of a table without dropping and recreating the table.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3550340" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx#3550334</link><pubDate>Mon, 04 Feb 2013 22:26:45 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3550334</guid><dc:creator>mbourgon</dc:creator><description>&lt;p&gt;Say I run a query using invoke-sqlcmd2, then need to add a field to the datatable (preferably at the beginning of the row) prior to using write-datatable. &amp;nbsp;How do I do this? &amp;nbsp;I&amp;#39;ve been futzing with add-member without any success. &amp;nbsp;Any help greatly appreciated!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3550334" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx#3434981</link><pubDate>Sun, 12 Jun 2011 18:01:37 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3434981</guid><dc:creator>cmille19</dc:creator><description>&lt;p&gt;inanutshell&lt;/p&gt;
&lt;p&gt;See discussion under Out-Datatable for how to handle text files:&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://gallery.technet.microsoft.com/ScriptCenter/4208a159-a52e-4b99-83d4-8048468d29dd/"&gt;gallery.technet.microsoft.com/.../4208a159-a52e-4b99-83d4-8048468d29dd&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3434981" width="1" height="1"&gt;</description></item><item><title>re: Use PowerShell to Collect Server Data and Write to SQL</title><link>http://blogs.technet.com/b/heyscriptingguy/archive/2010/11/01/use-powershell-to-collect-server-data-and-write-to-sql.aspx#3433616</link><pubDate>Mon, 06 Jun 2011 15:34:46 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3433616</guid><dc:creator>inanutshell</dc:creator><description>&lt;p&gt;I&amp;#39;m using get-content on a text file, and then using the select object on those results. &amp;nbsp;Finally I&amp;#39;m piping that to out-datatable, but get nothing but the length column. &amp;nbsp;Since I guess what is getting passed is a string array the actual string value is not grabbed from $object.PsObject.get_properties() in the out-datatable definition. &amp;nbsp;Is this by design? Does out-datatable not work with string arrays?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3433616" width="1" height="1"&gt;</description></item></channel></rss>