{"id":3900,"date":"2014-07-02T11:30:03","date_gmt":"2014-07-02T15:30:03","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=3900"},"modified":"2014-07-02T11:30:03","modified_gmt":"2014-07-02T15:30:03","slug":"sql-database-reports-with-powershell","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/","title":{"rendered":"SQL Database Reports with PowerShell"},"content":{"rendered":"<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-1688\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png\" alt=\"talkbubble\" width=\"198\" height=\"208\" \/><\/a>Last year I wrote an article for SQL Server Pro called <a href=\"http:\/\/sqlmag.com\/powershell\/powershell-sql-server-way\" target=\"_blank\">PowerShell in SQL Server<\/a>. In the article I provided an introduction to using PowerShell and the SQL Server module to do perform some typical management tasks. I think this type of information is especially important for those of you who have to manage a SQL Server but perhaps aren't really a DBA. The other day I received an email about a way to list all databases and their associated files. While I go over that somewhat in the original article, I thought I'd revisit and expand a bit on the topic here.<\/p>\n<p>In order for this to work you need the SQLPS module. Or you should be able to use PowerShell remoting with Invoke-Command. On my Windows 8.1 desktop I have the free SQL 2012 Express edition, primarily so that I can have access to the PowerShell module and specifically the Invoke-SQLCMD cmdlet which allows me to run a T-SQL command from my desktop to any SQL server. But that's not on the plate today.<\/p>\n<p>Instead we're going to take advantage of the SQL Server provider. When you import the SQLPS module, you will get a new PSDrive called SQLSERVER:.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive01.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3901\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive01-300x101.png\" alt=\"sqlpsdrive01\" width=\"300\" height=\"101\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive01-300x101.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive01-1024x346.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive01.png 1137w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>I can now navigate my SQL server instance like a file system.<\/p>\n<pre class=\"lang:ps decode:true \">cd .\\SQL\\jh-win81-ent\\default\\databases<\/pre>\n<p>I changed to the SQL \"folder\" then to the server (jh-win81-ent-01 is my local host) and then to the named instance, in this case Default and finally the Databases container.<br \/>\n<a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive02.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3903\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive02-300x130.png\" alt=\"sqlpsdrive02\" width=\"300\" height=\"130\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive02-300x130.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive02-1024x444.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive02.png 1137w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Now that I know where to look I display just the information I want.<\/p>\n<pre class=\"lang:ps decode:true \">dir sqlserver:\\sql\\jh-win81-ent\\default\\databases | \r\nSelect Name,Size,SpaceAvailable,PrimaryFilePath<\/pre>\n<p>I discovered these properties by using Get-Member and piping to Select *.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive03.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3904\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive03-300x106.png\" alt=\"sqlpsdrive03\" width=\"300\" height=\"106\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive03-300x106.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive03-1024x362.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive03.png 1137w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><br \/>\nOnce I know the properties, it is pretty easy to display the required information. The challenge was to display databases and their files. The file information is buried a little bit but not that really difficult to access.<\/p>\n<pre class=\"lang:ps decode:true \">dir sqlserver:\\sql\\jh-win81-ent\\default\\databases | \r\nSelect Name,Size,SpaceAvailable,PrimaryFilePath,\r\n@{Name=\"Path\";Expression={$_.Filegroups.files.filename}},\r\n@{Name=\"LogPath\";Expression={$_.LogFiles.filename}},\r\n@{Name=\"LogSize\";Expression={$_.LogFiles.Size}}<\/pre>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive04.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3905\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive04-300x153.png\" alt=\"sqlpsdrive04\" width=\"300\" height=\"153\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive04-300x153.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive04-1024x525.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqlpsdrive04.png 1137w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>By the way, the sizes are in MB. The results are objects like anything else in PowerShell so you could sort, filter, export, convert or whatever you need to do with this information. I think I'll create an HTML report.<\/p>\n<pre class=\"lang:ps decode:true \">$head = @\"\r\n&lt;Title&gt;SQL Database Report&lt;\/Title&gt;\r\n&lt;style&gt;\r\nbody { background-color:#FFFFFF;\r\n       font-family:Tahoma;\r\n       font-size:10pt; }\r\ntd, th { border:1px solid black; \r\n         border-collapse:collapse; }\r\nth { color:white;\r\n     background-color:black; }\r\ntable, tr, td, th { padding: 2px; margin: 0px }\r\ntr:nth-child(odd) {background-color: lightgray}\r\ntr:nth-child(odd) {background-color: lightgray}\r\ntable { width:95%;margin-left:5px; margin-bottom:20px;}\r\n&lt;\/style&gt;\r\n&lt;br&gt;\r\n&lt;H1&gt;SQL Database Report&lt;\/H1&gt;\r\n\"@\r\n\r\ndir sqlserver:\\sql\\jh-win81-ent\\default\\databases | \r\nSelect Name,Size,SpaceAvailable,PrimaryFilePath,\r\n@{Name=\"Path\";Expression={$_.Filegroups.files.filename}},\r\n@{Name=\"LogPath\";Expression={$_.LogFiles.filename}},\r\n@{Name=\"LogSize\";Expression={$_.LogFiles.Size}} | \r\nConvertto-html -Head $head  -PreContent \"&lt;H2&gt;$env:Computername&lt;\/H2&gt;\" -PostContent \"All sizes are in MB.&lt;br&gt;&lt;I&gt;Report run $(Get-Date)&lt;\/I&gt;\" |\r\nOut-File c:\\work\\sqldbreport.htm<\/pre>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqldbreport.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-3906\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqldbreport-300x120.png\" alt=\"sqldbreport\" width=\"300\" height=\"120\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqldbreport-300x120.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqldbreport-1024x409.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/07\/sqldbreport.png 1272w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Assuming the current credentials have the right permissions on a remote SQL Server, you can also do this remotely. Simply change the machine name in the path. Here's my modified HTML report code.<\/p>\n<pre class=\"lang:ps decode:true \">$Computername = \"Win81-ent-01\"\r\n\r\n$head = @\"\r\n&lt;Title&gt;SQL Database Report - $($computername.ToUpper())&lt;\/Title&gt;\r\n&lt;style&gt;\r\nbody { background-color:#FFFFFF;\r\n       font-family:Tahoma;\r\n       font-size:10pt; }\r\ntd, th { border:1px solid black; \r\n         border-collapse:collapse; }\r\nth { color:white;\r\n     background-color:black; }\r\ntable, tr, td, th { padding: 2px; margin: 0px }\r\ntr:nth-child(odd) {background-color: lightgray}\r\ntr:nth-child(odd) {background-color: lightgray}\r\ntable { width:95%;margin-left:5px; margin-bottom:20px;}\r\n&lt;\/style&gt;\r\n&lt;br&gt;\r\n&lt;H1&gt;SQL Database Report&lt;\/H1&gt;\r\n\"@\r\n\r\ndir sqlserver:\\sql\\$computername\\default\\databases | \r\nSelect Name,Size,SpaceAvailable,PrimaryFilePath,\r\n@{Name=\"Path\";Expression={$_.Filegroups.files.filename}},\r\n@{Name=\"LogPath\";Expression={$_.LogFiles.filename}},\r\n@{Name=\"LogSize\";Expression={$_.LogFiles.Size}} | \r\nConvertto-html -Head $head  -PreContent \"&lt;H2&gt;$Computername&lt;\/H2&gt;\" -PostContent \"All sizes are in MB.&lt;br&gt;&lt;I&gt;Report run $(Get-Date)&lt;\/I&gt;\" |\r\nOut-File \"c:\\work\\sqldbreport-$computername.htm\"<\/pre>\n<p>If you run into performance or timing issues, simply use remoting.<\/p>\n<pre class=\"lang:ps decode:true \" >$sb = {\r\nImport-module SQLPS\r\ndir sqlserver:\\sql\\$env:computername\\default\\databases |\r\nSelect Name,Size,SpaceAvailable,PrimaryFilePath,\r\n@{Name=\"Path\";Expression={$_.Filegroups.files.filename}},\r\n@{Name=\"LogPath\";Expression={$_.LogFiles.filename}},\r\n@{Name=\"LogSize\";Expression={$_.LogFiles.Size}} \r\n}\r\n\r\ninvoke-command -ScriptBlock $sb -ComputerName $computername -HideComputerName | \r\nSelect Name,Size,SpaceAvailable,PrimaryFilePath,Path,LogPath,Logsize |\r\nConvertto-html -Head $head  -PreContent \"&lt;H2&gt;$Computername&lt;\/H2&gt;\" -PostContent \"All sizes are in MB.&lt;br&gt;&lt;I&gt;Report run $(Get-Date)&lt;\/I&gt;\" |\r\nOut-File \"c:\\work\\sqldbreport-$computername.htm\"<\/pre>\n<p>Remoting is a great option if you need to use alternate credentials or if you want to process several SQL Servers at once.<\/p>\n<p>PowerShell works the same whether you are looking at a process, event log or SQL Server database. Once you master the fundamentals there's no end to what you can accomplish.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last year I wrote an article for SQL Server Pro called PowerShell in SQL Server. In the article I provided an introduction to using PowerShell and the SQL Server module to do perform some typical management tasks. I think this type of information is especially important for those of you who have to manage a&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"New from the blog: #SQL Server Database Reports with #PowerShell http:\/\/bit.ly\/1rXeAoA","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4,431],"tags":[468,534,577],"class_list":["post-3900","post","type-post","status-publish","format-standard","hentry","category-powershell","category-sql-server","tag-database","tag-powershell","tag-sql-server"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>SQL Database Reports with PowerShell &#8226; The Lonely Administrator<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Database Reports with PowerShell &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Last year I wrote an article for SQL Server Pro called PowerShell in SQL Server. In the article I provided an introduction to using PowerShell and the SQL Server module to do perform some typical management tasks. I think this type of information is especially important for those of you who have to manage a...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2014-07-02T15:30:03+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"SQL Database Reports with PowerShell\",\"datePublished\":\"2014-07-02T15:30:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/\"},\"wordCount\":454,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/talkbubble.png\",\"keywords\":[\"Database\",\"PowerShell\",\"SQL Server\"],\"articleSection\":[\"PowerShell\",\"SQL Server\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/\",\"name\":\"SQL Database Reports with PowerShell &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/talkbubble.png\",\"datePublished\":\"2014-07-02T15:30:03+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/#primaryimage\",\"url\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/talkbubble.png\",\"contentUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/10\\\/talkbubble.png\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/3900\\\/sql-database-reports-with-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL Database Reports with PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SQL Database Reports with PowerShell &#8226; The Lonely Administrator","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"SQL Database Reports with PowerShell &#8226; The Lonely Administrator","og_description":"Last year I wrote an article for SQL Server Pro called PowerShell in SQL Server. In the article I provided an introduction to using PowerShell and the SQL Server module to do perform some typical management tasks. I think this type of information is especially important for those of you who have to manage a...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/","og_site_name":"The Lonely Administrator","article_published_time":"2014-07-02T15:30:03+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"SQL Database Reports with PowerShell","datePublished":"2014-07-02T15:30:03+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/"},"wordCount":454,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png","keywords":["Database","PowerShell","SQL Server"],"articleSection":["PowerShell","SQL Server"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/","name":"SQL Database Reports with PowerShell &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png","datePublished":"2014-07-02T15:30:03+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/#primaryimage","url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png","contentUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/talkbubble.png"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3900\/sql-database-reports-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"SQL Database Reports with PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":5675,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/5675\/powershell-reminders-now-in-beta\/","url_meta":{"origin":3900,"position":0},"title":"PowerShell Reminders now in Beta","author":"Jeffery Hicks","date":"October 6, 2017","format":false,"excerpt":"For awhile now I've been working on a PowerShell project that I use every day. I am always in a PowerShell prompt and because I always seem to have little things like phone calls or family events that I need to keep track of, I wrote a \"tickler\" system. The\u2026","rel":"","context":"In &quot;GitHub&quot;","block_context":{"text":"GitHub","link":"https:\/\/jdhitsolutions.com\/blog\/category\/github\/"},"img":{"alt_text":"image","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/image_thumb.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/image_thumb.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/image_thumb.png?resize=525%2C300 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2017\/10\/image_thumb.png?resize=700%2C400 2x"},"classes":[]},{"id":9422,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9422\/introducing-psreminderlite\/","url_meta":{"origin":3900,"position":1},"title":"Introducing PSReminderLite","author":"Jeffery Hicks","date":"August 14, 2024","format":false,"excerpt":"For several years, I have been using a PowerShell module I wrote called MyTickle to help me manage my reminders and events. I spend my days at a PowerShell prompt, and I wanted an easy way to keep track of upcoming events. The module relied on a SQL Server or\u2026","rel":"","context":"In &quot;GitHub&quot;","block_context":{"text":"GitHub","link":"https:\/\/jdhitsolutions.com\/blog\/category\/github\/"},"img":{"alt_text":"PSReminderTags","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2024\/08\/remindertags-300x148.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":3361,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/3361\/creating-styling-html-reports-with-powershell\/","url_meta":{"origin":3900,"position":2},"title":"Creating Styling HTML Reports with PowerShell","author":"Jeffery Hicks","date":"August 26, 2013","format":false,"excerpt":"Last month I did an updated version of my presentation on creating styling HTML reports in Windows PowerShell. This presentation was for the PowerShell virtual chapter of SQL PASS. As such, I came up with some SQL related demonstrations and fine tuned some demos from earlier presentations. You can download\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":4435,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4435\/sql-database-report-revised\/","url_meta":{"origin":3900,"position":3},"title":"SQL Database Report Revised","author":"Jeffery Hicks","date":"July 3, 2015","format":false,"excerpt":"Last year I wrote an article that explained how to use the SQLSERVER PSDrive to create an HTML report highlighting some server and database information. If you want a refresher you can find that article here. In short, you can install the SQL Server PowerShell module on your client desktop\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"sqldatabases","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2015\/07\/sqldatabases-300x160.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1801,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1801\/finding-files-in-the-path-a-pipeline-perk\/","url_meta":{"origin":3900,"position":4},"title":"Finding Files in the Path &#8211; A Pipeline Perk","author":"Jeffery Hicks","date":"November 17, 2011","format":false,"excerpt":"I've been chipping in on a forum post about finding if a given file exists in any folder within the system environmental %PATH% variable using Windows PowerShell. There are several ways you might approach this. But the best way in my opinion is to leverage the PowerShell pipeline. Perhaps you\u2026","rel":"","context":"In &quot;Scripting&quot;","block_context":{"text":"Scripting","link":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":9117,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9117\/organizing-chaos-with-psworkitems-and-powershell\/","url_meta":{"origin":3900,"position":5},"title":"Organizing Chaos with PSWorkItems and PowerShell","author":"Jeffery Hicks","date":"August 3, 2022","format":false,"excerpt":"I spend my working days living in a PowerShell console. Over the years, I've developed many PowerShell modules to help me manage the chaos that is my work life. One area that always demands attention is managing my tasks and To-Dos. For several years I have been using the MyTasks\u2026","rel":"","context":"In &quot;PowerShell&quot;","block_context":{"text":"PowerShell","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/08\/get-psworkitem.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/08\/get-psworkitem.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/08\/get-psworkitem.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/08\/get-psworkitem.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3900","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=3900"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3900\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}