{"id":1546,"date":"2011-07-04T11:02:50","date_gmt":"2011-07-04T15:02:50","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=1546"},"modified":"2011-07-04T11:08:15","modified_gmt":"2011-07-04T15:08:15","slug":"get-top-level-folder-usage","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/","title":{"rendered":"Get Top Level Folder Usage"},"content":{"rendered":"<p>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.<\/p>\n<p>[cc lang=\"PowerShell\"]<br \/>\n$folder=\"S:\\\"<br \/>\ndir $folder | where {$_.psIscontainer} | foreach {<br \/>\n$stat= dir $_.fullname -recurse | Measure-Object -property length -Sum<br \/>\nNew-Object PSObject -property @{Folder=$_.FullName;Files=$stat.count;Size=$stat.Sum;}}<br \/>\n[\/cc]<\/p>\n<p>Again, this would be handy to turn into a function or scriptblock.  This is far from perfect. For example, it doesn't like empty folders. But this should be a good starting point for your own script or function.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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=&#8221;PowerShell&#8221;] $folder=&#8221;S:\\&#8221; dir $folder | where {$_.psIscontainer} | foreach { $stat= dir $_.fullname -recurse | Measure-Object -property length -Sum New-Object PSObject -property @{Folder=$_.FullName;Files=$stat.count;Size=$stat.Sum;}} [\/cc] Again,&#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":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[75],"tags":[97,303,534],"class_list":["post-1546","post","type-post","status-publish","format-standard","hentry","category-powershell-v2-0","tag-filesystem","tag-get-childitemmeasure-object","tag-powershell"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Get Top Level Folder Usage &#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-v2-0\/1546\/get-top-level-folder-usage\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Top Level Folder Usage &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"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=&quot;PowerShell&quot;] $folder=&quot;S:&quot; dir $folder | where {$_.psIscontainer} | foreach { $stat= dir $_.fullname -recurse | Measure-Object -property length -Sum New-Object PSObject -property @{Folder=$_.FullName;Files=$stat.count;Size=$stat.Sum;}} [\/cc] Again,...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2011-07-04T15:02:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2011-07-04T15:08:15+00:00\" \/>\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<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-v2-0\\\/1546\\\/get-top-level-folder-usage\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-v2-0\\\/1546\\\/get-top-level-folder-usage\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Get Top Level Folder Usage\",\"datePublished\":\"2011-07-04T15:02:50+00:00\",\"dateModified\":\"2011-07-04T15:08:15+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-v2-0\\\/1546\\\/get-top-level-folder-usage\\\/\"},\"wordCount\":103,\"commentCount\":5,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"keywords\":[\"FileSystem\",\"Get-ChildItem;Measure-Object\",\"PowerShell\"],\"articleSection\":[\"PowerShell v2.0\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-v2-0\\\/1546\\\/get-top-level-folder-usage\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-v2-0\\\/1546\\\/get-top-level-folder-usage\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-v2-0\\\/1546\\\/get-top-level-folder-usage\\\/\",\"name\":\"Get Top Level Folder Usage &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"datePublished\":\"2011-07-04T15:02:50+00:00\",\"dateModified\":\"2011-07-04T15:08:15+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-v2-0\\\/1546\\\/get-top-level-folder-usage\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-v2-0\\\/1546\\\/get-top-level-folder-usage\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-v2-0\\\/1546\\\/get-top-level-folder-usage\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell v2.0\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell-v2-0\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get Top Level Folder Usage\"}]},{\"@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":"Get Top Level Folder Usage &#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-v2-0\/1546\/get-top-level-folder-usage\/","og_locale":"en_US","og_type":"article","og_title":"Get Top Level Folder Usage &#8226; The Lonely Administrator","og_description":"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 PSObject -property @{Folder=$_.FullName;Files=$stat.count;Size=$stat.Sum;}} [\/cc] Again,...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/","og_site_name":"The Lonely Administrator","article_published_time":"2011-07-04T15:02:50+00:00","article_modified_time":"2011-07-04T15:08:15+00:00","author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Get Top Level Folder Usage","datePublished":"2011-07-04T15:02:50+00:00","dateModified":"2011-07-04T15:08:15+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/"},"wordCount":103,"commentCount":5,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"keywords":["FileSystem","Get-ChildItem;Measure-Object","PowerShell"],"articleSection":["PowerShell v2.0"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/","name":"Get Top Level Folder Usage &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"datePublished":"2011-07-04T15:02:50+00:00","dateModified":"2011-07-04T15:08:15+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell v2.0","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-v2-0\/"},{"@type":"ListItem","position":2,"name":"Get Top Level Folder Usage"}]},{"@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":407,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/","url_meta":{"origin":1546,"position":0},"title":"Is That Folder Empty?","author":"Jeffery Hicks","date":"September 30, 2009","format":false,"excerpt":"In keeping with my recent trend of offering solutions based on PowerShell v2.0, here's a function I've revised to test if a folder is empty. I can't recall where I used the original function or if I ever did. But I came across it recently and decided to give it\u2026","rel":"","context":"In &quot;CommandLine&quot;","block_context":{"text":"CommandLine","link":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/zrtn_003p5cb42026_tn.jpg?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":1721,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/1721\/simple-where-filters\/","url_meta":{"origin":1546,"position":1},"title":"Simple Where Filters","author":"Jeffery Hicks","date":"October 26, 2011","format":false,"excerpt":"The comment about how awkward it is in PowerShell to filter out folders with Get-ChidlItem, or its alias dir, came up the other day on Twitter. I'll be the first to admit that running a DIR command and wanting to skip folders, or perhaps you only want top level folders,\u2026","rel":"","context":"In &quot;CommandLine&quot;","block_context":{"text":"CommandLine","link":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/10\/filterfunnel.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":3014,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/","url_meta":{"origin":1546,"position":2},"title":"Getting Top Level Folder Report in PowerShell","author":"Jeffery Hicks","date":"May 9, 2013","format":false,"excerpt":"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\u2026","rel":"","context":"In &quot;Conferences&quot;","block_context":{"text":"Conferences","link":"https:\/\/jdhitsolutions.com\/blog\/category\/conferences\/"},"img":{"alt_text":"foldersize","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/05\/foldersize-1024x589.png?resize=525%2C300 1.5x"},"classes":[]},{"id":4449,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4449\/measure-that-folder-with-powershell-revisited\/","url_meta":{"origin":1546,"position":3},"title":"Measure that Folder with PowerShell Revisited","author":"Jeffery Hicks","date":"July 15, 2015","format":false,"excerpt":"Last year I posted a PowerShell function to measure the size of a folder. I recently had a need to use it again, and realized it needed a few tweaks. By default, the original version recursively searched through all subfolders. But there may be situations where you only want to\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":2330,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2330\/friday-fun-get-latest-powershell-scripts\/","url_meta":{"origin":1546,"position":4},"title":"Friday Fun: Get Latest PowerShell Scripts","author":"Jeffery Hicks","date":"May 18, 2012","format":false,"excerpt":"Probably like many of you I keep almost all of my scripts in a single location. I'm also usually working on multiple items at the same time. Some times I have difficult remembering the name of a script I might have been working on a few days ago that I\u2026","rel":"","context":"In &quot;Friday Fun&quot;","block_context":{"text":"Friday Fun","link":"https:\/\/jdhitsolutions.com\/blog\/category\/friday-fun\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2012\/05\/get-latestscript-300x133.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4305,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4305\/what-powershell-script-was-i-working-on\/","url_meta":{"origin":1546,"position":5},"title":"What PowerShell Script Was I Working On?","author":"Jeffery Hicks","date":"March 24, 2015","format":false,"excerpt":"Last week I shared a script for finding recently modified files in a given directory. In fact, it wouldn't be that difficult to find the last files I was working on and open them in the PowerShell ISE. Assuming my Get-RecentFile function is loaded it is a simple as this:\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\/1546","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=1546"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1546\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}