{"id":26311,"date":"2016-06-30T16:23:47","date_gmt":"2016-06-30T16:23:47","guid":{"rendered":"https:\/\/test.simple-talk.com\/uncategorized\/invoke-sqlcmd-just-got-better\/"},"modified":"2016-10-17T08:52:01","modified_gmt":"2016-10-17T08:52:01","slug":"invoke-sqlcmd-just-got-better","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/blogs\/invoke-sqlcmd-just-got-better\/","title":{"rendered":"Invoke-SqlCmd Just Got Better!"},"content":{"rendered":"<p>If you&#8217;ve read even just a few of my articles on Simple-Talk you know that I&#8217;m a big fan of PowerShell + SQL Server.\u00a0 Over the years I have written a lot about how to collect data from your SQL Servers and store it somewhere, maybe in a database, maybe in a<a href=\"https:\/\/www.simple-talk.com\/sql\/database-administration\/automating-your-sql-server-best-practice-reports-the-document\/\"> word document<\/a>.<\/p>\n<p>Well today collecting data from your SQL Servers just got <a href=\"https:\/\/blogs.technet.microsoft.com\/dataplatforminsider\/2016\/06\/30\/sql-powershell-july-2016-update\/\">a little bit easier<\/a>.<\/p>\n<h2>Invoke-Sqlcmd<\/h2>\n<p>Invoke-Sqlcmd now supports a -OutputAs parameter and it allow you to specify either &#8220;DataRows&#8221; (default), &#8220;DataTables&#8221;, and &#8220;DataSet&#8221;.\u00a0 We have had this functionality for years with <a href=\"https:\/\/gallery.technet.microsoft.com\/scriptcenter\/7985b7ef-ed89-4dfd-b02a-433cc4e30894\">Invoke-SqlCmd2<\/a> and it&#8217;s now available natively from SQL Server.\u00a0 When you run a query and output it into a DataTable you will still need some other mechanism to be able to store the data.\u00a0 At this point you have lots of options, you could store the data in Excel, HTML, or put it into a table in another SQL Server database.<\/p>\n<h2>Write-DataTable<\/h2>\n<p>For right now you will still need to use a script like <a href=\"https:\/\/gallery.technet.microsoft.com\/scriptcenter\/2fdeaf8d-b164-411c-9483-99413d6053ae\">Write-DataTable<\/a> if you want to put your data back into a table in SQL Server.\u00a0\u00a0 While this means you might still need an additional script to accomplish a common task, the great news is that Matteo from the SQL Tools team has already commented on this <a href=\"https:\/\/trello.com\/c\/7HbLhAQH\">Trello card<\/a> saying that looking into adding that functionality.\u00a0 I encourage you to go Up-Vote &amp; comment on that item on <a href=\"http:\/\/sqlps.io\/vote\">Trello<\/a> or on <a href=\"http:\/\/bit.ly\/WriteTable\">Connect<\/a>.<\/p>\n<h2>Join the Conversations!<\/h2>\n<p>As I mentioned above, folks in the PowerShell + SQL Server community are collaborating on the Trello board about new cmdlets they want; and everyone is welcome to comment &amp; Up-Vote.\u00a0 If you want to be able to add a card, just ask and you will be added!\u00a0 In addition, a Slack channel has been setup for everyone in SQL Community to join.\u00a0 You can go to <a href=\"http:\/\/sqlps.io\/slack\">this link here<\/a> and auto-invite yourself.\u00a0 Everyone is welcome to join; I can&#8217;t wait to talk to you on the boards!<\/p>\n<h2>But wait, there&#8217;s more.<\/h2>\n<ul>\n<li>To read the full announcement from Microsoft check out <a href=\"https:\/\/blogs.technet.microsoft.com\/dataplatforminsider\/2016\/06\/30\/sql-powershell-july-2016-update\/\">this post<\/a> on the Data Platform Insider blog.<\/li>\n<li>To read more about the new SQL Agent cmdlets read <a href=\"https:\/\/blog.netnerds.net\/2016\/06\/the-sql-server-powershell-module-formerly-known-as-sqlps\/\">this post<\/a> from Chrissy LeMaire.<\/li>\n<li>To read more about the new Get-SqlErrorLog cmdlet read <a href=\"http:\/\/sqlvariant.com\/2016\/06\/webinar-on-25-new-powershell-cmdlets-for-sql-server-and-more\">this post<\/a> from Aaron Nelson.<\/li>\n<\/ul>\n<p>Microsoft also said &#8220;Additionally, we added the ConnectionString parameter which allows the script author complete control over the connection context. This unlocks new capabilities such as connecting to SQL Azure using Azure Active Directory authentication.<\/p>\n<p>Big thanks to Aaron, Chrissy and Rob . This blog post it is just a channel to spread the words, the post itself is from all of us. The PASS PowerShell VC Team.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve read even just a few of my articles on Simple-Talk you know that I&#8217;m a big fan of PowerShell + SQL Server.\u00a0 Over the years I have written a lot about how to collect data from your SQL Servers and store it somewhere, maybe in a database, maybe in a word document. Well&#8230;&hellip;<\/p>\n","protected":false},"author":221715,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[],"coauthors":[6819],"class_list":["post-26311","post","type-post","status-publish","format-standard","hentry","category-blogs"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/26311","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/221715"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=26311"}],"version-history":[{"count":10,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/26311\/revisions"}],"predecessor-version":[{"id":68717,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/26311\/revisions\/68717"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=26311"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=26311"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=26311"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=26311"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}