{"id":3014,"date":"2013-05-09T12:34:39","date_gmt":"2013-05-09T16:34:39","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=3014"},"modified":"2013-05-09T12:34:39","modified_gmt":"2013-05-09T16:34:39","slug":"getting-top-level-folder-report-in-powershell","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/","title":{"rendered":"Getting Top Level Folder Report in PowerShell"},"content":{"rendered":"<p>One of the sessions I presented recently at TechDays San Francisco was on file share management with PowerShell. One of the scripts I demonstrated was for a function to get information for top level folders. This is the type of thing that could be handy to run say against the root of your shared users folder. Or the root of a group share where each subfolder is a share that belongs to a different group. My function takes advantage of a new feature for Get-ChildItem that makes it much easier to retrieve only file or directories. Here's my Get-FolderSize function.<\/p>\n<pre class=\"lang:ps decode:true\">#requires -version 3.0\r\n\r\nFunction Get-FolderSize {\r\n\r\n&lt;#\r\n.Synopsis\r\nGet a top level folder size report\r\n.Description\r\nThis command will analyze the top level folders in a given root. It will write\r\na custom object to the pipeline that shows the number of files in each folder,\r\nthe total size in bytes and folder attributes. The output will also include \r\nfiles in the root of the specified path.\r\n\r\nSample output:\r\nName       : DesktopTileResources\r\nFullname   : C:\\windows\\DesktopTileResources\r\nSize       : 21094\r\nCount      : 17\r\nAttributes : ReadOnly, Directory\r\n\r\nUse the -Force parameter to include hidden directories.\r\n.Example\r\nPS C:\\&gt; get-foldersize c:\\work | format-table -auto\r\n\r\nPath               Name             Size Count Attributes\r\n----               ----             ---- ----- ----------\r\nC:\\work            work        252083656   223  Directory\r\nC:\\work\\atomic     atomic         622445     6  Directory\r\nC:\\work\\fooby      fooby              18     1  Directory\r\nC:\\work\\images     images        1470091   118  Directory\r\nC:\\work\\resources  resources     8542561   143  Directory\r\nC:\\work\\shell      shell          225161     4  Directory\r\nC:\\work\\test       test         17198758     4  Directory\r\nC:\\work\\Test Rig 2 Test Rig 2    4194304     1  Directory\r\nC:\\work\\test2      test2              40     2  Directory\r\nC:\\work\\Ubuntu12   Ubuntu12   7656701952     2  Directory\r\nC:\\work\\widgets    widgets        162703    49  Directory\r\n\r\n.Example\r\nPS C:\\&gt; get-foldersize c:\\users\\jeff\\ -force | out-gridview -title Jeff\r\n.Notes\r\nLast Updated: May 8, 2013\r\nVersion     : 0.9\r\n\r\n  ****************************************************************\r\n  * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *\r\n  * THOROUGHLY IN A LAB ENVIRONMENT. USE AT YOUR OWN RISK.  IF   *\r\n  * YOU DO NOT UNDERSTAND WHAT THIS SCRIPT DOES OR HOW IT WORKS, *\r\n  * DO NOT USE IT OUTSIDE OF A SECURE, TEST SETTING.             *\r\n  ****************************************************************\r\n.Link\r\nhttp:\/\/jdhitsolutions.com\/blog\/2013\/05\/getting-top-level-folder-report-in-powershell\r\n.Inputs\r\nNone\r\n.Outputs\r\nCustom object\r\n#&gt;\r\n\r\n[cmdletbinding()]\r\nParam(\r\n[Parameter(Position=0)]\r\n[ValidateScript({Test-Path $_})]\r\n[string]$Path=\".\",\r\n[switch]$Force\r\n)\r\n\r\nWrite-Verbose \"Starting $($myinvocation.MyCommand)\"\r\nWrite-Verbose \"Analyzing $path\"\r\n\r\n#define a hashtable of parameters to splat to Get-ChildItem\r\n$dirParams = @{\r\nPath = $Path\r\nErrorAction = \"Stop\"\r\nErrorVariable = \"myErr\"\r\nDirectory = $True\r\n}\r\n\r\nif ($hidden) {\r\n    $dirParams.Add(\"Force\",$True)\r\n}\r\n$activity = $myinvocation.MyCommand\r\n\r\nWrite-Progress -Activity $activity -Status \"Getting top level folders\" -CurrentOperation $Path\r\n\r\n$folders = Get-ChildItem @dirParams\r\n\r\n#process each folder\r\n$folders | \r\nforeach -begin {\r\n     Write-Verbose $Path\r\n     #initialize some total counters\r\n     $totalFiles = 0\r\n     $totalSize = 0\r\n     #initialize a counter for progress bar\r\n     $i=0\r\n\r\n     Try {     \r\n        #measure files in $Path root\r\n        Write-Progress -Activity $activity -Status $Path -CurrentOperation \"Measuring root folder\" -PercentComplete 0\r\n        #modify dirParams hashtable\r\n        $dirParams.Remove(\"Directory\")\r\n        $dirParams.Add(\"File\",$True)\r\n        $stats = Get-ChildItem @dirParams | Measure-Object -Property length -sum\r\n     }\r\n     Catch {\r\n        $msg = \"Error: $($myErr[0].ErrorRecord.CategoryInfo.Category) $($myErr[0].ErrorRecord.CategoryInfo.TargetName)\"\r\n        Write-Warning $msg\r\n     }\r\n     #increment the grand totals\r\n     $totalFiles+= $stats.Count\r\n     $totalSize+= $stats.sum\r\n\r\n     if ($stats.count -eq 0) {\r\n        #set size to 0 if the top level folder is empty\r\n        $size = 0\r\n     }\r\n     else {\r\n        $size=$stats.sum\r\n     }\r\n\r\n     $root = Get-Item -Path $path\r\n     #define properties for the custom object\r\n     $hash = [ordered]@{\r\n         Path = $root.FullName\r\n         Name = $root.Name\r\n         Size = $size\r\n         Count = $stats.count\r\n         Attributes = (Get-Item $path).Attributes\r\n         }\r\n     #write the object for the folder root\r\n     New-Object -TypeName PSobject -Property $hash\r\n\r\n    } -process { \r\n     Try {\r\n        Write-Verbose $_.fullname\r\n        $i++\r\n        [int]$percomplete = ($i\/$folders.count)*100\r\n        Write-Progress -Activity $activity -Status $_.fullname -CurrentOperation \"Measuring folder\" -PercentComplete $percomplete\r\n\r\n        #get directory information for top level folders\r\n        $dirParams.Path = $_.Fullname\r\n        $stats = Get-ChildItem @dirParams -Recurse | Measure-Object -Property length -sum\r\n     }\r\n     Catch {\r\n        $msg = \"Error: $($myErr[0].ErrorRecord.CategoryInfo.Category) $($myErr[0].ErrorRecord.CategoryInfo.TargetName)\"\r\n        Write-Warning $msg\r\n     }\r\n     #increment the grand totals\r\n     $totalFiles+= $stats.Count\r\n     $totalSize+= $stats.sum\r\n\r\n     if ($stats.count -eq 0) {\r\n        #set size to 0 if the top level folder is empty\r\n       $size = 0\r\n     }\r\n     else {\r\n        $size=$stats.sum\r\n     }\r\n     #define properties for the custom object\r\n     $hash = [ordered]@{\r\n         Path = $_.FullName\r\n         Name = $_.Name\r\n         Size = $size\r\n         Count = $stats.count\r\n         Attributes = $_.Attributes\r\n        }\r\n     #write the object for each top level folder\r\n     New-Object -TypeName PSobject -Property $hash\r\n } -end {\r\n    Write-Progress -Activity $activity -Status \"Finished\" -Completed\r\n    Write-Verbose \"Total number of files for $path = $totalfiles\"\r\n    Write-Verbose \"Total file size in bytes for $path = $totalsize\"\r\n }\r\n\r\n Write-Verbose \"Ending $($myinvocation.MyCommand)\"\r\n } #end Get-FolderSize<\/pre>\n<p>The function defaults to the local path and gets a collection of all of the top level folders, that is, those found directly in the root. The function then takes the collection of folders and pipes them to ForEach-Object. Most of the time we only use the Process scriptblock with ForEach-Object, but I want to take advantage of the Begin and End blocks as well. In the Begin scriptblock I measure all of the files in the root of the parent path and create a custom object that shows the number of files and total size in bytes. I'm going to get this same information for each child folder as well.<\/p>\n<p>The process scriptblock does just that for each top level folder. This version of my function uses Write-Progress to display progress and in the End script block I have code to complete the progress bar, although It works just fine without it.<\/p>\n<p>Other techniques I'd like to point out are the use of splatting and error handling. You'll notice that I'm using the common -ErrorVariable parameter. After exploring the different types of exceptions I decided I could easily display any errors and the paths In the Catch block. I'm using Write-Warning, but this could just as easily be written to a text file.<\/p>\n<p>The function writes an object like this for every folder.<\/p>\n<pre class=\"lang:batch decode:true \">Path       : C:\\windows\\Inf\r\nName       : Inf\r\nSize       : 81926300\r\nCount      : 1265\r\nAttributes : Directory<\/pre>\n<p>Here's an example of complete output:<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-3016\" alt=\"foldersize\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.png\" width=\"625\" height=\"359\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.png 1024w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-300x172.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-624x359.png 624w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize.png 1137w\" sizes=\"auto, (max-width: 625px) 100vw, 625px\" \/><\/a>Because I've written objects to the pipeline, I could pipe this to Out-Gridview, export to a CSV file or create an HTML report.<\/p>\n<p>This is just a taste of what you can accomplish with some basic PowerShell commands.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the sessions I presented recently at TechDays San Francisco was on file share management with PowerShell. One of the scripts I demonstrated was for a function to get information for top level folders. This is the type of thing that could be handy to run say against the root of your shared users&#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":"Getting Top Level Folder Report in #PowerShell","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":[134,359,8],"tags":[137,178,534,397,540],"class_list":["post-3014","post","type-post","status-publish","format-standard","hentry","category-conferences","category-powershell-3-0","category-scripting","tag-get-childitem","tag-measure-object","tag-powershell","tag-reporting","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Getting Top Level Folder Report in 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\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Getting Top Level Folder Report in PowerShell &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"One of the sessions I presented recently at TechDays San Francisco was on file share management with PowerShell. One of the scripts I demonstrated was for a function to get information for top level folders. This is the type of thing that could be handy to run say against the root of your shared users...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2013-05-09T16:34:39+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.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\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Getting Top Level Folder Report in PowerShell\",\"datePublished\":\"2013-05-09T16:34:39+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/\"},\"wordCount\":384,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/05\\\/foldersize-1024x589.png\",\"keywords\":[\"Get-ChildItem\",\"Measure-Object\",\"PowerShell\",\"Reporting\",\"Scripting\"],\"articleSection\":[\"Conferences\",\"Powershell 3.0\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/\",\"name\":\"Getting Top Level Folder Report in PowerShell &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/05\\\/foldersize-1024x589.png\",\"datePublished\":\"2013-05-09T16:34:39+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/05\\\/foldersize.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/05\\\/foldersize.png\",\"width\":1137,\"height\":655},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/3014\\\/getting-top-level-folder-report-in-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Conferences\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/conferences\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Getting Top Level Folder Report in 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":"Getting Top Level Folder Report in 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\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Getting Top Level Folder Report in PowerShell &#8226; The Lonely Administrator","og_description":"One of the sessions I presented recently at TechDays San Francisco was on file share management with PowerShell. One of the scripts I demonstrated was for a function to get information for top level folders. This is the type of thing that could be handy to run say against the root of your shared users...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/","og_site_name":"The Lonely Administrator","article_published_time":"2013-05-09T16:34:39+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.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\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Getting Top Level Folder Report in PowerShell","datePublished":"2013-05-09T16:34:39+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/"},"wordCount":384,"commentCount":5,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.png","keywords":["Get-ChildItem","Measure-Object","PowerShell","Reporting","Scripting"],"articleSection":["Conferences","Powershell 3.0","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/","name":"Getting Top Level Folder Report in PowerShell &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.png","datePublished":"2013-05-09T16:34:39+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize.png","width":1137,"height":655},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Conferences","item":"https:\/\/jdhitsolutions.com\/blog\/category\/conferences\/"},{"@type":"ListItem","position":2,"name":"Getting Top Level Folder Report in 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":3551,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/","url_meta":{"origin":3014,"position":0},"title":"PowerShell Clean Up Tools","author":"Jeffery Hicks","date":"November 11, 2013","format":false,"excerpt":"A few years ago I think I posted some PowerShell clean up tools. These were functions designed to help clear out old files, especially for folders like TEMP. Recently I decided to upgrade them to at least PowerShell 3.0 to take advantage of v3 cmdlets and features. I use these\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":"021913_2047_WordTest1.png","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/021913_2047_WordTest1.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":2673,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2673\/friday-fun-edit-recent-file\/","url_meta":{"origin":3014,"position":1},"title":"Friday Fun: Edit Recent File","author":"Jeffery Hicks","date":"January 4, 2013","format":false,"excerpt":"As you might imagine I work on a lot of PowerShell projects at the same time. Sometimes I'll start something at the beginning of the week and then need to come back to it at the end of the week. The problem is that I can't always remembered what I\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":"Edit-RecentFile","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/01\/Edit-RecentFile-300x209.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":9057,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9057\/using-powershell-your-way\/","url_meta":{"origin":3014,"position":2},"title":"Using PowerShell Your Way","author":"Jeffery Hicks","date":"June 6, 2022","format":false,"excerpt":"I've often told people that I spend my day in a PowerShell prompt. I run almost my entire day with PowerShell. I've shared many of the tools I use daily on Github. Today, I want to share another way I have PowerShell work the way I need it, with minimal\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\/06\/dl.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2022\/06\/dl.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":7317,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7317\/fast-folder-sizes-with-powershell\/","url_meta":{"origin":3014,"position":3},"title":"Fast Folder Sizes with PowerShell","author":"Jeffery Hicks","date":"February 25, 2020","format":false,"excerpt":"I am always looking for ways to do things faster and easier with PowerShell. One common task that I never seem to stop needing is discovering how much disk space a given folder is consuming. Even though disk space is cheap these days, I guess I'm old-school enough to want\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\/2020\/02\/getfoldersize3.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/getfoldersize3.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/getfoldersize3.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/getfoldersize3.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/getfoldersize3.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/02\/getfoldersize3.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":3715,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3715\/friday-fun-the-measure-of-a-folder\/","url_meta":{"origin":3014,"position":4},"title":"Friday Fun: The Measure of a Folder","author":"Jeffery Hicks","date":"February 21, 2014","format":false,"excerpt":"Last week, I demonstrated how to measure a file with PowerShell. This week let's go a step further and measure a folder. I'm going to continue to use Measure-Object although this time I will need to use it to measure numeric property values. Here's the complete function after which I'll\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"ruler","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2014\/02\/ruler-150x150.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1546,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/","url_meta":{"origin":3014,"position":5},"title":"Get Top Level Folder Usage","author":"Jeffery Hicks","date":"July 4, 2011","format":false,"excerpt":"This is too long to tweet, even written as a one liner. But this will search a folder for top level subfolders and return the file usage for each. [cc lang=\"PowerShell\"] $folder=\"S:\\\" dir $folder | where {$_.psIscontainer} | foreach { $stat= dir $_.fullname -recurse | Measure-Object -property length -Sum New-Object\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":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3014","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=3014"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3014\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}