{"id":80,"date":"2018-09-29T06:44:52","date_gmt":"2018-09-29T06:44:52","guid":{"rendered":"http:\/\/www.spktechfit.com\/?p=80"},"modified":"2018-09-29T06:44:52","modified_gmt":"2018-09-29T06:44:52","slug":"how-to-export-spiceworks-reports-to-html-using-powershell","status":"publish","type":"post","link":"https:\/\/www.spktechfit.com\/?p=80","title":{"rendered":"How To Export Spiceworks Reports to HTML Using Powershell"},"content":{"rendered":"<div id=\"how_to_intro\">\n<div class=\"introduction steps-content sui-opt-in\">\n<h1>Introduction<\/h1>\n<p>This allows you to query the Spiceworks database and save the results as a HTML report. It uses the PSSQLite Powerhsell module and then the &#8216;ConvertTo-HTML&#8217; command to output it to HTML.<\/p>\n<\/div>\n<\/div>\n<div class=\"steps-section sui-opt-in\">\n<div class=\"step-header\">\n<h2>Step 1: Create your SQL Query<\/h2>\n<\/div>\n<div class=\"step-content\">\n<p>It is best to run your test query&#8217;s against a copy of your Spiceworks database, not your live database. There are a number of tools that allow you to query and browse the database. I like to use\u00a0<a href=\"http:\/\/sqlitebrowser.org\/\" target=\"_blank\" rel=\"nofollow noreferrer noopener\">http:\/\/sqlitebrowser.org\/<\/a>\u00a0. This will show the database schema and allow you to build and test your queries.<\/p>\n<p>A sample query to show all current open tickets:<br \/>\nselect<br \/>\n(select (first_name || &#8216; &#8216; || last_name) as &#8216;Created By&#8217; from users where tickets.created_by=users.id) AS &#8216;Created By&#8217;<br \/>\n, SUBSTR(summary,1,255) AS Summary<br \/>\n,tickets.created_at as &#8216;Created&#8217;<br \/>\nfrom<br \/>\ntickets<br \/>\nwhere status = &#8216;open&#8217;<\/p>\n<\/div>\n<div class=\"step-header\">\n<h2>Step 2: Install the PSSQLite Module<\/h2>\n<\/div>\n<div class=\"step-content\">\n<p>if you have PowerShell 5, or the PowerShellGet module, do the following:<br \/>\n&#8211; Open Powershell as an Administrator<br \/>\n&#8211; Run the following command:\u00a0Install-Module PSSQLite<\/p>\n<p>&#8211; Then run the following to import the module: Import-Module PSSQLite<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/content.spiceworksstatic.com\/service.community\/p\/how_to_step_attachments\/0000128030\/5baf194d\/attached_file\/b9a9823c715adf711cc45ef8f98bc490e502de8611f1e1bb2b000e7311b11ae2_ImportModule.png\" alt=\"\" \/><\/p>\n<p>Alternatively, you can download the module, extract it, then import it. See the following for more instructions on that:\u00a0\u00a0<a href=\"https:\/\/github.com\/RamblingCookieMonster\/PSSQLite#instructions\" target=\"_blank\" rel=\"nofollow noreferrer noopener\">https:\/\/github.com\/RamblingCookieMonster\/PSSQLite#instructions<\/a><\/p>\n<div class=\"steps-section sui-opt-in\">\n<div class=\"how-to-step steps-content \">\n<div class=\"step-header\">\n<h2>Step 3: Set the datasource as your Spiceworks database copy<\/h2>\n<\/div>\n<div class=\"step-content\">\n<p>Create a variable and assign it the path to your copy of the Spiceworks database.<br \/>\nEG:<br \/>\n<em>$DataSource = &#8220;C:\\Backup\\Spiceworks_Prod.db&#8221;<\/em><img decoding=\"async\" src=\"https:\/\/content.spiceworksstatic.com\/service.community\/p\/how_to_step_attachments\/0000128031\/5baf195e\/attached_file\/73ad411047a11b69e194406eeee958d298101f42d52cfc62666a152eae3987ce_datasource.png\" alt=\"\" \/><\/p>\n<\/div>\n<\/div>\n<div class=\"how-to-step steps-content \">\n<div class=\"step-header\">\n<h2>Step 4: Setup your Query in Powershell<\/h2>\n<\/div>\n<div class=\"step-content\">\n<p>Create a variable and assign it the string of your SQL query.<br \/>\nEG:<br \/>\n<em>$Query = &#8220;select\u00a0<\/em><br \/>\n<em>(select (first_name || &#8216; &#8216; || last_name) as &#8216;Created By&#8217; from users where tickets.created_by=users.id) AS &#8216;Created By&#8217; &#8212; gets users first name and last name on the id number\u00a0<\/em><br \/>\n<em>, SUBSTR(summary,1,255) AS Summary\u00a0<\/em><br \/>\n<em>,tickets.created_at as &#8216;Created&#8217;\u00a0<\/em><br \/>\n<em>from\u00a0<\/em><br \/>\n<em>tickets\u00a0<\/em><br \/>\n<em>where status = &#8216;open&#8217;\u00a0<\/em><br \/>\n<em>&#8220;<\/em><img decoding=\"async\" src=\"https:\/\/content.spiceworksstatic.com\/service.community\/p\/how_to_step_attachments\/0000128032\/5baf196f\/attached_file\/b4623ab00aa992693006bfeb0af6ff7e1edbfe5a858fa7069d2ab536c45fd138_Query.png\" alt=\"\" \/><\/p>\n<\/div>\n<\/div>\n<div class=\"how-to-step steps-content \">\n<div class=\"step-header\">\n<h2>Step 5: Run the query and export to HTML<\/h2>\n<\/div>\n<div class=\"step-content\">\n<p>At this stage we invoke the PSSQLite command using the datasource and query we created, then export it to html using the ConvertTo-html command.<\/p>\n<p><em>Invoke-SqliteQuery -DataSource $DataSource -Query $Query | ConvertTo-html -Title &#8220;Daily Report&#8221; -Body (get-date) &gt; C:\\SpiceworksReport.htm<\/em><img decoding=\"async\" src=\"https:\/\/content.spiceworksstatic.com\/service.community\/p\/how_to_step_attachments\/0000128033\/5baf197f\/attached_file\/ffe074fbb4384fa29673265e656b29c96818a8ce36c50b9b627885fe581d134d_InvokeCommand.png\" alt=\"\" \/><\/p>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"reference-section sui-opt-in\">\n<h2>References<\/h2>\n<ul class=\"references\">\n<li><a href=\"http:\/\/ramblingcookiemonster.github.io\/SQLite-and-PowerShell\/\" target=\"_blank\" rel=\"nofollow noopener\">SQLite and Powershell<\/a><\/li>\n<li><a href=\"http:\/\/sqlitebrowser.org\/\" target=\"_blank\" rel=\"nofollow noopener\">SQLite Browser<\/a><\/li>\n<\/ul>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Introduction This allows you to query the Spiceworks database and save the results as a HTML report. It uses the PSSQLite Powerhsell module and then the &#8216;ConvertTo-HTML&#8217; command to output it to HTML. Step 1: Create your SQL Query It is best to run your test query&#8217;s against a copy of your Spiceworks database, not [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":82,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[8,9,3],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts\/80"}],"collection":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=80"}],"version-history":[{"count":1,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts\/80\/revisions"}],"predecessor-version":[{"id":81,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/posts\/80\/revisions\/81"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=\/wp\/v2\/media\/82"}],"wp:attachment":[{"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=80"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=80"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spktechfit.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=80"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}