{"id":1522,"date":"2011-06-23T11:03:43","date_gmt":"2011-06-23T15:03:43","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=1522"},"modified":"2013-10-07T11:01:12","modified_gmt":"2013-10-07T15:01:12","slug":"get-file-utilization-by-extension","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/","title":{"rendered":"Get File Utilization by Extension"},"content":{"rendered":"<p>In the past I've posted a few PowerShell functions that provide all types of file and folder information. The other day I had a reason to revisit one of them and I spent a little time revising and expanding. This new function, Get-Extension will search a given folder and create a custom object for each file extension showing the total number of files, the total size, the average size, the maximum size and the largest size. At it's core, the function takes output from Get-ChildItem and pipes it to Measure-Object. But I've incorporated features such as filtering and the ability to run the entire function as a background job.<\/p>\n<p>By default, the function searches the top level of your $ENV:Temp folder and returns a custom object for each file type.<\/p>\n<pre class=\"lang:batch decode:true \" >PS C:\\&gt; get-extension | sort TotalSize -Descending | Select -first 1\r\nAnalyzing C:\\Users\\Jeff\\AppData\\Local\\Temp\r\n\r\nAverage : 402240.857142857\r\nLargest : 2655668\r\nPath : C:\\Users\\Jeff\\AppData\\Local\\Temp\r\nTotalSize : 2815686\r\nExtension : log\r\nCount : 7\r\nSmallest : 134\r\n<\/pre>\n<p>Here's how this works.<\/p>\n<pre class=\"lang:ps decode:true \" >Function Get-Extension {\r\n\r\n[cmdletbinding(DefaultParameterSetName=\"*\")]\r\n\r\nParam (\r\n[Parameter(Position=0)]\r\n[validateNotNullorEmpty()]\r\n[string]$Path=$env:temp,\r\n[Parameter(ParameterSetName=\"Filter\")]\r\n[string[]]$Include,\r\n[Parameter(ParameterSetName=\"Filter\")]\r\n[string[]]$Exclude,\r\n[Parameter()]\r\n[switch]$Recurse,\r\n[switch]$Force,\r\n[switch]$AsJob\r\n)\r\n\r\nWrite-Verbose \"Starting $($myinvocation.mycommand)\"\r\n\r\n#Automatically turn on recursion if -Include or -Exclude is used\r\nif ($Include -OR $Exclude) {\r\n$Recurse=$True\r\n}\r\n\r\n#test and see if path is valid\r\nif (Test-Path -Path $path) {\r\n\r\n#Verify we are using a FileSystem path\r\nif ((Get-Item -Path $path).PSProvider.Name -ne \"FileSystem\") {\r\nWrite-Warning \"$($path.ToUpper()) is not a valid file system path.\"\r\nReturn\r\n}\r\n\r\n#define a variable for message to be displayed when the search begins\r\n$msg=\"Analyzing $path\"\r\n\r\n#build a command string based on parameters\r\n$cmd=\"Get-ChildItem -Path $path\"\r\nif ($recurse) {\r\n$msg+=\" recursively\"\r\n$cmd+=\" -recurse\"\r\n}\r\nif ($include) {\r\n$ofs=\",\"\r\n$msg+=\" include $($Include -as [string])\"\r\n$cmd+=\" -include $($Include -as [string])\"\r\n}\r\nif ($exclude) {\r\n$ofs=\",\"\r\n$msg+=\" exclude $($Exclude -as [string])\"\r\n$cmd+=\" -exclude $($Exclude -as [string])\"\r\n}\r\nif ($force) {\r\n$cmd+=\" -force\"\r\n}\r\n\r\n#wrap the core commands into a scriptblock so it can be executed directly\r\n#or used with Start-Job\r\n$sb={Param([string]$cmd,[string]$Path)\r\nWrite-Host $msg -ForegroundColor Green\r\n\r\n#get all files but exclude folders\r\nWrite-Verbose \"Executing: $cmd\"\r\n$files= Invoke-Expression $cmd | where {-NOT $_.PSIsContainer}\r\n\r\n#put files into groups based on extension\r\n$group=$files | Group-Object -Property Extension\r\nWrite-Verbose \"Found $($group.count) file extensions\"\r\n\r\nforeach ($extension in ($group | Sort Name)) {\r\n#calculate statistics for each group\r\nWrite-Verbose \"Measuring $($extension.name)\"\r\n$stats=$extension.group | measure-object -Average -Sum -Minimum -Maximum -Property length\r\n\r\n#trim off the period from the extension if it exists\r\nif ($extension.name -match \"\\.\") {\r\n$ext=$extension.name.Substring(1)\r\n}\r\nelse {\r\n$ext=$extension.name\r\n}\r\n\r\n#write a custom object to the pipeline\r\nNew-Object -TypeName PSObject -Property @{\r\nCount=$stats.count\r\n#trim off the period\r\nExtension=$ext\r\nTotalSize=$stats.sum\r\nLargest=$stats.maximum\r\nSmallest=$stats.minimum\r\nAverage=$stats.average\r\nPath=$Path\r\n}\r\n} #foreach\r\n}#$sb\r\nif ($AsJob) {\r\nWrite-Verbose \"Creating background job\"\r\nStart-Job -ScriptBlock $sb -ArgumentList $cmd,$path\r\n}\r\nelse {\r\nInvoke-Command -ScriptBlock $sb -ArgumentList $cmd,$path\r\n}\r\n} #if\r\nelse {\r\nWrite-Warning \"Failed to find $path\"\r\n}\r\n\r\nWrite-Verbose \"Ending $($myinvocation.mycommand)\"\r\n\r\n} #end function\r\n<\/pre>\n<p>The function uses a few parameters from Get-ChildItem, like -Include, -Exclude and -Force. If you use one of the filtering parameters, then you also need to use -Recurse. You can specify it, or the function will automatically enable it if it detects -Include or -Exclude.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\nif ($Include -OR $Exclude) {\r\n$Recurse=$True\r\n}\r\n<\/pre>\n<p>Obviously (I hope), this only works on the file system. But I went ahead and added some code to verify that the specified path is from the FileSystem provider.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\nif ((Get-Item -Path $path).PSProvider.Name -ne \"FileSystem\") {\r\nWrite-Warning \"$($path.ToUpper()) is not a valid file system path.\"\r\nReturn\r\n}\r\n<\/pre>\n<p>Normally, I'm not a big fan of Return. But in this situation it is exactly what I want since I want to terminate the pipeline. I could have also thrown an exception here but decided not to get that wild. Assuming the path is valid, the function builds a command string based on the specified parameters.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\n#build a command string based on parameters\r\n$cmd=\"Get-ChildItem -Path $path\"\r\nif ($recurse) {\r\n$msg+=\" recursively\"\r\n$cmd+=\" -recurse\"\r\n}\r\nif ($include) {\r\n$ofs=\",\"\r\n$msg+=\" include $($Include -as [string])\"\r\n$cmd+=\" -include $($Include -as [string])\"\r\n}\r\nif ($exclude) {\r\n$ofs=\",\"\r\n$msg+=\" exclude $($Exclude -as [string])\"\r\n$cmd+=\" -exclude $($Exclude -as [string])\"\r\n}\r\nif ($force) {\r\n$cmd+=\" -force\"\r\n}\r\n<\/pre>\n<p>The function will invoke this string using Invoke-Expression and filter out any folders since all I care about are files.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\n#get all files but exclude folders\r\nWrite-Verbose \"Executing: $cmd\"\r\n$files= Invoke-Expression $cmd | where {-NOT $_.PSIsContainer}\r\n\r\n#put files into groups based on extension\r\n$group=$files | Group-Object -Property Extension\r\n<\/PRE>\r\n\r\nThe results are then grouped using Group-Object. Each extension group is piped to Measure-Object to calculate the statistics based on the file's length property.\r\n\r\n<pre class=\"lang:ps decode:true \" >\r\nforeach ($extension in ($group | Sort Name)) {\r\n#calculate statistics for each group\r\nWrite-Verbose \"Measuring $($extension.name)\"\r\n$stats=$extension.group | measure-object -Average -Sum -Minimum -Maximum -Property length\r\n<\/PRE>\r\n\r\nLastly, the function creates a custom object representing each file extension using the New-Object cmdlet.\r\n\r\n<pre class=\"lang:ps decode:true \" >\r\nNew-Object -TypeName PSObject -Property @{\r\nCount=$stats.count\r\n#trim off the period\r\nExtension=$ext\r\nTotalSize=$stats.sum\r\nLargest=$stats.maximum\r\nSmallest=$stats.minimum\r\nAverage=$stats.average\r\nPath=$Path\r\n}\r\n<\/pre>\n<p>Because I'm writing an object tot he pipeline you can further sort, filter, export or whatever. This is what makes PowerShell so flexible and valuable to IT Pros.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/get-extension.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-1528\" title=\"get-extension\" alt=\"\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/get-extension-300x131.png\" width=\"300\" height=\"131\" srcset=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/get-extension-300x131.png 300w, https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/get-extension.png 987w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>One thing I quickly realized, was that scanning a large folder such as Documents folder or a file share UNC, could take a long time. I could use Start-Job with my original function, but it was a bit awkward. So I decided to include -AsJob as a parameter and move the job command into the function itself. This works because I take the entire core command and wrap it in a script block.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\n$sb={Param([string]$cmd,[string]$Path)\r\nWrite-Host $msg -ForegroundColor Green\r\n\r\n#get all files but exclude folders\r\nWrite-Verbose \"Executing: $cmd\"\r\n$files= Invoke-Expression $cmd | where {-NOT $_.PSIsContainer}\r\n...\r\n<\/pre>\n<p>Because of scope the scriptblock needs parameters so I can pass it my command string and the Path variable which are used within the scriptblock. After $sb has been defined, if -AsJob was specified, the function uses Start-Job to create a background job. Otherwise, it uses Invoke-Command to execute it interactively.<\/p>\n<pre class=\"lang:ps decode:true \" >\r\nif ($AsJob) {\r\nWrite-Verbose \"Creating background job\"\r\nStart-Job -ScriptBlock $sb -ArgumentList $cmd,$path\r\n}\r\nelse {\r\nInvoke-Command -ScriptBlock $sb -ArgumentList $cmd,$path\r\n}\r\n<\/pre>\n<p>Use the normal job cmdlets to get the results and manage the job. But now I can run something like this:<\/p>\n<pre class=\"lang:batch decode:true \" >\r\nPS C:\\> Get-Extension $env:userprofile\\documents -include *.doc*,*.ppt*,*.xls* -AsJob\r\n\r\nId Name State HasMoreData Location Command\r\n-- ---- ----- ----------- -------- -------\r\n31 Job31 Running True localhost Param([string]$cmd)...\r\n<\/pre>\n<p>As always I hope you'll let me know how this works for you. The complete script has comment based help and an optional line to uncomment at the end to create an alias for the function.<\/p>\n<p>Download <a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/Get-Extension.txt\" target=\"_blank\">Get-Extension<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the past I&#8217;ve posted a few PowerShell functions that provide all types of file and folder information. The other day I had a reason to revisit one of them and I spent a little time revising and expanding. This new function, Get-Extension will search a given folder and create a custom object for each&#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,8],"tags":[123,137,299,298,202,178,534],"class_list":["post-1522","post","type-post","status-publish","format-standard","hentry","category-powershell-v2-0","category-scripting","tag-files","tag-get-childitem","tag-group-ojbect","tag-invoke-expression","tag-jobs","tag-measure-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 File Utilization by Extension &#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\/1522\/get-file-utilization-by-extension\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get File Utilization by Extension &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"In the past I&#039;ve posted a few PowerShell functions that provide all types of file and folder information. The other day I had a reason to revisit one of them and I spent a little time revising and expanding. This new function, Get-Extension will search a given folder and create a custom object for each...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2011-06-23T15:03:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2013-10-07T15:01:12+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/get-extension-300x131.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=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Get File Utilization by Extension\",\"datePublished\":\"2011-06-23T15:03:43+00:00\",\"dateModified\":\"2013-10-07T15:01:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/\"},\"wordCount\":548,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/06\\\/get-extension-300x131.png\",\"keywords\":[\"Files\",\"Get-ChildItem\",\"Group-Ojbect\",\"Invoke-Expression\",\"Jobs\",\"Measure-Object\",\"PowerShell\"],\"articleSection\":[\"PowerShell v2.0\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/\",\"name\":\"Get File Utilization by Extension &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/06\\\/get-extension-300x131.png\",\"datePublished\":\"2011-06-23T15:03:43+00:00\",\"dateModified\":\"2013-10-07T15:01:12+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/06\\\/get-extension.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2011\\\/06\\\/get-extension.png\",\"width\":\"987\",\"height\":\"434\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/1522\\\/get-file-utilization-by-extension\\\/#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 File Utilization by Extension\"}]},{\"@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 File Utilization by Extension &#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\/1522\/get-file-utilization-by-extension\/","og_locale":"en_US","og_type":"article","og_title":"Get File Utilization by Extension &#8226; The Lonely Administrator","og_description":"In the past I've posted a few PowerShell functions that provide all types of file and folder information. The other day I had a reason to revisit one of them and I spent a little time revising and expanding. This new function, Get-Extension will search a given folder and create a custom object for each...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/","og_site_name":"The Lonely Administrator","article_published_time":"2011-06-23T15:03:43+00:00","article_modified_time":"2013-10-07T15:01:12+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/get-extension-300x131.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":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Get File Utilization by Extension","datePublished":"2011-06-23T15:03:43+00:00","dateModified":"2013-10-07T15:01:12+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/"},"wordCount":548,"commentCount":1,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/get-extension-300x131.png","keywords":["Files","Get-ChildItem","Group-Ojbect","Invoke-Expression","Jobs","Measure-Object","PowerShell"],"articleSection":["PowerShell v2.0","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/","name":"Get File Utilization by Extension &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/get-extension-300x131.png","datePublished":"2011-06-23T15:03:43+00:00","dateModified":"2013-10-07T15:01:12+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/get-extension.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2011\/06\/get-extension.png","width":"987","height":"434"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/1522\/get-file-utilization-by-extension\/#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 File Utilization by Extension"}]},{"@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":3014,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/","url_meta":{"origin":1522,"position":0},"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":3715,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3715\/friday-fun-the-measure-of-a-folder\/","url_meta":{"origin":1522,"position":1},"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":8622,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8622\/finding-modified-files-with-powershell\/","url_meta":{"origin":1522,"position":2},"title":"Finding Modified Files with PowerShell","author":"Jeffery Hicks","date":"October 14, 2021","format":false,"excerpt":"Here's another task that I seem to be constantly fiddling with using PowerShell. What files did I work on yesterday? Or what files were modified in the last 48 hours? Obviously, Get-ChildItem is going to be the primary command. It is simple enough to get files based on an extension\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\/2021\/10\/extension-report.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/extension-report.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/10\/extension-report.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":4449,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4449\/measure-that-folder-with-powershell-revisited\/","url_meta":{"origin":1522,"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":7317,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7317\/fast-folder-sizes-with-powershell\/","url_meta":{"origin":1522,"position":4},"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":1546,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/","url_meta":{"origin":1522,"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\/1522","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=1522"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1522\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1522"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1522"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1522"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}