{"id":2766,"date":"2013-01-30T13:24:08","date_gmt":"2013-01-30T18:24:08","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=2766"},"modified":"2013-01-30T13:24:08","modified_gmt":"2013-01-30T18:24:08","slug":"building-excel-reports-with-powershell","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/","title":{"rendered":"Building Excel Reports with PowerShell"},"content":{"rendered":"<p>Last year I wrote a series of articles for the Petri IT KnowledgeBase on using Microsoft Excel with PowerShell. Today I received an email from a reader who had a question about article that showed how to <a href=\"http:\/\/www.petri.co.il\/export-to-excel-with-powershell-part-2.htm\" title=\"read the original article\" target=\"_blank\">build a drive usage report<\/a> in Excel. In the article I suggest it wouldn't be too difficult to modify my sample code to create a worksheet for each computer. Perhaps I was a bit too glib. So I decided to revise my sample script so that you could pass an array of computernames and build a single workbook with a named worksheet for each computer.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n#Requires -version 2.0<\/p>\n<p><#\nthis version takes an array of computer names and creates a new\nworksheet for each one.\n#><\/p>\n<p>[cmdletbinding()]<br \/>\nParam([string[]]$computername=$env:computername)<\/p>\n<p>#I hope it goes without saying that Excel needs to be installed<br \/>\nWrite-Verbose \"Creating Excel application\"<br \/>\n$xl=New-Object -ComObject \"Excel.Application\"<br \/>\n$wb=$xl.Workbooks.Add()<\/p>\n<p>#we'll need some constants<br \/>\n$xlConditionValues=[Microsoft.Office.Interop.Excel.XLConditionValueTypes]<br \/>\n$xlTheme=[Microsoft.Office.Interop.Excel.XLThemeColor]<br \/>\n$xlChart=[Microsoft.Office.Interop.Excel.XLChartType]<br \/>\n$xlIconSet=[Microsoft.Office.Interop.Excel.XLIconSet]<br \/>\n$xlDirection=[Microsoft.Office.Interop.Excel.XLDirection]<\/p>\n<p>Foreach ($computer in $computername) {<br \/>\n    #get disk data<br \/>\n    Write-Verbose \"Getting disk data from $computer\"<br \/>\n    $disks=Get-WmiObject -Class Win32_LogicalDisk -ComputerName $computer -Filter \"DriveType=3\"<\/p>\n<p>    Write-Verbose \"Adding Worksheet\"<br \/>\n    $ws=$wb.Worksheets.Add()<\/p>\n<p>    $cells=$ws.Cells<\/p>\n<p>    $cells.item(1,1)=\"Disk Drive Report\"<\/p>\n<p>    #define some variables to control navigation<br \/>\n    $row=3<br \/>\n    $col=1<\/p>\n<p>    #insert column headings<br \/>\n    Write-Verbose \"Adding drive headings\" <\/p>\n<p>    \"Drive\",\"SizeGB\",\"FreespaceGB\",\"UsedGB\",\"%Free\",\"%Used\" | foreach {<br \/>\n        $cells.item($row,$col)=$_<br \/>\n        $cells.item($row,$col).font.bold=$True<br \/>\n        $col++<br \/>\n    }<\/p>\n<p>    Write-Verbose \"Adding drive data\"<br \/>\n    foreach ($drive in $disks) {<br \/>\n        $row++<br \/>\n        $col=1<br \/>\n        $cells.item($Row,$col)=$drive.DeviceID<br \/>\n        $col++<br \/>\n        $cells.item($Row,$col)=$drive.Size\/1GB<br \/>\n        $cells.item($Row,$col).NumberFormat=\"0\"<br \/>\n        $col++<br \/>\n        $cells.item($Row,$col)=$drive.Freespace\/1GB<br \/>\n        $cells.item($Row,$col).NumberFormat=\"0.00\"<br \/>\n        $col++<br \/>\n        $cells.item($Row,$col)=($drive.Size - $drive.Freespace)\/1GB<br \/>\n        $cells.item($Row,$col).NumberFormat=\"0.00\"<br \/>\n        $col++<br \/>\n        $cells.item($Row,$col)=($drive.Freespace\/$drive.size)<br \/>\n        $cells.item($Row,$col).NumberFormat=\"0.00%\"<br \/>\n        $col++<br \/>\n        $cells.item($Row,$col)=($drive.Size - $drive.Freespace) \/ $drive.size<br \/>\n        $cells.item($Row,$col).NumberFormat=\"0.00%\"<br \/>\n    }<\/p>\n<p>    Write-Verbose \"Adding some style\" <\/p>\n<p>    #add some style<br \/>\n    $range=$ws.range(\"A1\")<br \/>\n    $range.Style=\"Title\"<br \/>\n    #or set it like this<br \/>\n    $ws.Range(\"A3:F3\").Style = \"Heading 2\"<\/p>\n<p>    #adjust some column widths<br \/>\n    Write-Verbose \"Adjusting column widths\"<br \/>\n    $ws.columns.item(\"C:C\").columnwidth=15<br \/>\n    $ws.columns.item(\"D:F\").columnwidth=10.5<br \/>\n    $ws.columns.item(\"B:B\").EntireColumn.AutoFit() | out-null<\/p>\n<p>    #add some conditional formatting<br \/>\n    Write-Verbose \"Adding conditional formatting\" <\/p>\n<p>    #get the starting cell<br \/>\n    $start=$ws.range(\"F4\")<br \/>\n    #get the last cell<br \/>\n    $Selection=$ws.Range($start,$start.End($xlDirection::xlDown))<br \/>\n    #add the icon set<br \/>\n    $Selection.FormatConditions.AddIconSetCondition() | Out-Null<br \/>\n    $Selection.FormatConditions.item($($Selection.FormatConditions.Count)).SetFirstPriority()<br \/>\n    $Selection.FormatConditions.item(1).ReverseOrder = $True<br \/>\n    $Selection.FormatConditions.item(1).ShowIconOnly = $False<br \/>\n    $Selection.FormatConditions.item(1).IconSet = $xlIconSet::xl3TrafficLights1<br \/>\n    $Selection.FormatConditions.item(1).IconCriteria.Item(2).Type=$xlConditionValues::xlConditionValueNumber<br \/>\n    $Selection.FormatConditions.item(1).IconCriteria.Item(2).Value=0.8<br \/>\n    $Selection.FormatConditions.item(1).IconCriteria.Item(2).Operator=7<br \/>\n    $Selection.FormatConditions.item(1).IconCriteria.Item(3).Type=$xlConditionValues::xlConditionValueNumber<br \/>\n    $Selection.FormatConditions.item(1).IconCriteria.Item(3).Value=0.9<br \/>\n    $Selection.FormatConditions.item(1).IconCriteria.Item(3).Operator=7<\/p>\n<p>    #insert a graph<br \/>\n    Write-Verbose \"Creating a graph\"<br \/>\n    $chart=$ws.Shapes.AddChart().Chart<br \/>\n    $chart.chartType=$xlChart::xlBarClustered<\/p>\n<p>    $start=$ws.range(\"A3\")<br \/>\n    #get the last cell<br \/>\n    $Y=$ws.Range($start,$start.End($xlDirection::xlDown))<br \/>\n    $start=$ws.range(\"F3\")<br \/>\n    #get the last cell<br \/>\n    $X=$ws.Range($start,$start.End($xlDirection::xlDown))<\/p>\n<p>    $chartdata=$ws.Range(\"A$($Y.item(1).Row):A$($Y.item($Y.count).Row),F$($X.item(1).Row):F$($X.item($X.count).Row)\")<br \/>\n    $chart.SetSourceData($chartdata)<\/p>\n<p>    #add labels<br \/>\n    $chart.seriesCollection(1).Select() | Out-Null<br \/>\n    $chart.SeriesCollection(1).ApplyDataLabels() | out-Null<br \/>\n    #modify the chart title<br \/>\n    $chart.ChartTitle.Text = \"Utilization\"<br \/>\n    Write-Verbose \"Repositioning graph\"<br \/>\n    $ws.shapes.item(\"Chart 1\").top=40<br \/>\n    $ws.shapes.item(\"Chart 1\").left=400<\/p>\n<p>    Write-Verbose \"Renaming the worksheet\"<br \/>\n    #rename the worksheet<br \/>\n    $name=$disks[0].SystemName<br \/>\n    $ws.Name=$name<br \/>\n    #select A1<br \/>\n    $ws.Range(\"A1\").Select() | Out-Null<br \/>\n} #foreach<\/p>\n<p>#delete extra sheets<br \/>\nWrite-Verbose \"Deleting extra worksheets\"<br \/>\n$xl.worksheets.Item(\"Sheet1\").Delete()<br \/>\n$xl.Worksheets.Item(\"Sheet2\").Delete()<br \/>\n$xl.Worksheets.Item(\"Sheet3\").Delete()<\/p>\n<p>#make Excel visible<br \/>\n$xl.Visible=$True<\/p>\n<p>$filepath=Read-Host \"Enter a path and filename to save the file\"<\/p>\n<p>if ($filepath) {<br \/>\n    Write-Verbose \"Saving file to $filepath\"<br \/>\n    $wb.SaveAs($filepath)<br \/>\n    $xl.displayAlerts=$False<br \/>\n    $wb.Close()<br \/>\n    $xl.Quit()<br \/>\n}<\/p>\n<p>#end of script<br \/>\n<\/code><\/p>\n<p>If you looked at the original post, here are the changes I made. First, I modified the script parameters to take an array of computer names.<\/p>\n<p><code><br \/>\nParam([string[]]$computername=$env:computername)<br \/>\n<\/code><\/p>\n<p>I decided to change the parameter name as well which worked out well because I could keep most of my code for each computer and simply insert a ForEach loop.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\nForeach ($computer in $computername) {<br \/>\n    #get disk data<br \/>\n    Write-Verbose \"Getting disk data from $computer\"<br \/>\n    $disks=Get-WmiObject -Class Win32_LogicalDisk -ComputerName $computer -Filter \"DriveType=3\"<br \/>\n...<br \/>\n<\/code><\/p>\n<p>This also meant I needed to move some code to before this loop since I only have to create the Excel application and workbook objects once. For each computer I use WMI to get disk data and create a new worksheet.<\/p>\n<p><code><br \/>\n    Write-Verbose \"Adding Worksheet\"<br \/>\n    $ws=$wb.Worksheets.Add()<br \/>\n<\/code><\/p>\n<p>The rest of the Excel-related code remains the same for each computer. But I did alter the code to rename each worksheet.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n#rename the worksheet<br \/>\n$name=$disks[0].SystemName<br \/>\n$ws.Name=$name<br \/>\n...<br \/>\n<\/code><\/p>\n<p>I also decided to delete the \"extra\" sheets. Unless you've modified Excel's startup behavior new workbooks have Sheet1, Sheet2 and Sheet3 which I don't need so I delete them.<\/p>\n<p><code lang=\"PowerShell\"><br \/>\n#delete extra sheets<br \/>\nWrite-Verbose \"Deleting extra worksheets\"<br \/>\n$xl.worksheets.Item(\"Sheet1\").Delete()<br \/>\n$xl.Worksheets.Item(\"Sheet2\").Delete()<br \/>\n$xl.Worksheets.Item(\"Sheet3\").Delete()<br \/>\n<\/code><\/p>\n<p>With this new script I can run a command like this:<\/p>\n<p><code lang=\"DOS\"><br \/>\nPS Scripts:\\> .\\New-ExcelDiskSpace2A.ps1 -computer novo8,jdhit-dc01 -Verbose<br \/>\n<\/code><\/p>\n<p>Which gives me a single workbook with a worksheet for each computer:<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport-1024x555.png\" alt=\"MultiExcelDiskReport\" width=\"625\" height=\"338\" class=\"aligncenter size-large wp-image-2768\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport-1024x555.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport-300x162.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport-624x338.png 624w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport.png 1128w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a><\/p>\n<p>Download my revised script <a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/New-ExcelDiskSpace2A.txt\" target='_blank'>New-ExcelDiskSpace2A<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last year I wrote a series of articles for the Petri IT KnowledgeBase on using Microsoft Excel with PowerShell. Today I received an email from a reader who had a question about article that showed how to build a drive usage report in Excel. In the article I suggest it wouldn&#8217;t be too difficult to&#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":"","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,8,19],"tags":[377,339,534,540,547],"class_list":["post-2766","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","category-wmi","tag-excel","tag-petri","tag-powershell","tag-scripting","tag-wmi"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Building Excel 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\/2766\/building-excel-reports-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Building Excel Reports with PowerShell &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"Last year I wrote a series of articles for the Petri IT KnowledgeBase on using Microsoft Excel with PowerShell. Today I received an email from a reader who had a question about article that showed how to build a drive usage report in Excel. In the article I suggest it wouldn&#039;t be too difficult to...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2013-01-30T18:24:08+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport-1024x555.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=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Building Excel Reports with PowerShell\",\"datePublished\":\"2013-01-30T18:24:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/\"},\"wordCount\":288,\"commentCount\":15,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/01\\\/MultiExcelDiskReport-1024x555.png\",\"keywords\":[\"Excel\",\"Petri\",\"PowerShell\",\"Scripting\",\"WMI\"],\"articleSection\":[\"PowerShell\",\"Scripting\",\"WMI\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/\",\"name\":\"Building Excel Reports with PowerShell &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/01\\\/MultiExcelDiskReport-1024x555.png\",\"datePublished\":\"2013-01-30T18:24:08+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/01\\\/MultiExcelDiskReport.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/01\\\/MultiExcelDiskReport.png\",\"width\":1128,\"height\":612},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/2766\\\/building-excel-reports-with-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Building Excel 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":"Building Excel 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\/2766\/building-excel-reports-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Building Excel Reports with PowerShell &#8226; The Lonely Administrator","og_description":"Last year I wrote a series of articles for the Petri IT KnowledgeBase on using Microsoft Excel with PowerShell. Today I received an email from a reader who had a question about article that showed how to build a drive usage report in Excel. In the article I suggest it wouldn't be too difficult to...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/","og_site_name":"The Lonely Administrator","article_published_time":"2013-01-30T18:24:08+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport-1024x555.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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Building Excel Reports with PowerShell","datePublished":"2013-01-30T18:24:08+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/"},"wordCount":288,"commentCount":15,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport-1024x555.png","keywords":["Excel","Petri","PowerShell","Scripting","WMI"],"articleSection":["PowerShell","Scripting","WMI"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/","name":"Building Excel Reports with PowerShell &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport-1024x555.png","datePublished":"2013-01-30T18:24:08+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/MultiExcelDiskReport.png","width":1128,"height":612},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2766\/building-excel-reports-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Building Excel 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":1413,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1413\/get-registry-size-and-age\/","url_meta":{"origin":2766,"position":0},"title":"Get Registry Size and Age","author":"Jeffery Hicks","date":"May 4, 2011","format":false,"excerpt":"I'm not sure why the registry has been on my mind lately. I probably need a vacation to get out more. But I put together a relatively simple Windows PowerShell function to retrieve registry statistics that you might find useful. My Get-Registry function will return information about the size of\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\/2011\/05\/registry.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1532,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1532\/get-local-administrators-with-wmi-and-powershell\/","url_meta":{"origin":2766,"position":1},"title":"Get Local Administrators with WMI and PowerShell","author":"Jeffery Hicks","date":"July 1, 2011","format":false,"excerpt":"Earlier this week I was helping someone out on a problem working with the local administrators group. There are a variety of ways to enumerate the members of a local group. The code he was using involved WMI. I hadn't really worked with the WMI approach in any great detail\u2026","rel":"","context":"In &quot;PowerShell v2.0&quot;","block_context":{"text":"PowerShell v2.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":88,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/88\/powershell-parsing\/","url_meta":{"origin":2766,"position":2},"title":"Powershell Parsing","author":"Jeffery Hicks","date":"January 16, 2007","format":false,"excerpt":"In PowerShell, Get-WMIObject is a terrific cmdlet for remotely managing systems. If you have a text list of server or computer names, here's a quick method you could enumerate that list and do something to each server.foreach ($server in (Get-Content s:\\servers.txt)) {#skip blank lines if (($server).length -gt 0) { $server\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":2369,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2369\/get-ip-addresses-with-powershell\/","url_meta":{"origin":2766,"position":3},"title":"Get IP Addresses with PowerShell","author":"Jeffery Hicks","date":"June 6, 2012","format":false,"excerpt":"In celebration of World IPv6 Day, I thought I'd post a little PowerShell code to return IP addresses for a computer. This information is stored in WMI with the Win32_NetworkAdapterConfiguration class. This class will return information about a number of virtual adapters as well so I find it easier to\u2026","rel":"","context":"In &quot;Scripting&quot;","block_context":{"text":"Scripting","link":"https:\/\/jdhitsolutions.com\/blog\/category\/scripting\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/06\/networkcables-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2342,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2342\/query-local-administrators-with-cim\/","url_meta":{"origin":2766,"position":4},"title":"Query Local Administrators with CIM","author":"Jeffery Hicks","date":"May 24, 2012","format":false,"excerpt":"Yesterday I posted an article on listing members of the local administrators group with PowerShell and Get-WmiObject. PowerShell 3.0 offers an additional way using the CIM cmdlets. The CIM cmdlets query the same WMI information, except instead of using the traditional RPC\/DCOM connection, these cmdlets utilize PowerShell's remoting endpoint so\u2026","rel":"","context":"In &quot;Powershell 3.0&quot;","block_context":{"text":"Powershell 3.0","link":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-3-0\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/05\/talkbubble-v3-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1369,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1369\/scripting-games-2001-beginner-event-5-commentary\/","url_meta":{"origin":2766,"position":5},"title":"Scripting Games 2011 Beginner Event 5 Commentary","author":"Jeffery Hicks","date":"April 25, 2011","format":false,"excerpt":"My commentary for Beginner Event 5 in the 2011 Scripting Games is now available. One item that seems to be missing on the ScriptingGuys site is my complete solution so I thought I would share it here, plus a variation. My sample solution is perhaps a little over-wrought for a\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":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2766","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=2766"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/2766\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=2766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=2766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=2766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}