{"id":407,"date":"2009-09-30T22:07:05","date_gmt":"2009-10-01T02:07:05","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=407"},"modified":"2009-10-01T09:02:40","modified_gmt":"2009-10-01T13:02:40","slug":"is-that-folder-empty","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/","title":{"rendered":"Is That Folder Empty?"},"content":{"rendered":"\n<p>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 a facelift. Manually determining if a folder is empty is pretty easy. If it doesn't have any files, I consider it empty. What I originally wanted was a way to find all empty folders, say from a given root folder. Once I've identified the folders I can do something with them like whack 'em. Here's my PowerShell v2 function.<\/p>\n<p> <!--more--> <\/p>\n<p><code>Function IsEmptyFolder { <br \/>#requires -version 2.0<\/code><\/p>\n<p><code>&lt;# <br \/>.Synopsis <br \/>Determine if a folder is empty of all files. <br \/>.Description <br \/>This function can be used to determine if a folder is empty of all files. It will ignore any subfolders, unless that subfolder includes files. If the folder is empty, the fullname is written to the pipeline. You can capture this information to a file or variable or pass it on to Remove-Item to delete the folder. <br \/>.Parameter Fullname <br \/>The full folder path to examine <br \/>.Example <br \/>PS C:\\&gt; IsEmptyFolder \"c:\\files\\test\" <\/p>\n<p>Will return the folder full name if c:\\files\\test has no files. <br \/>.Example <br \/>PS C:\\&gt; dir c:\\test r-recurse | where {$_.PSIsContainer} | IsEmptyFolder | Sort <\/p>\n<p>This is a bit more efficient as only directory paths are passed to the function. Output is sorted <br \/>by the fullname. <br \/>.Example <br \/>PS C:\\&gt; dir $env:temp -recurse | IsEmptyFolder | out-file Cleanup.txt <\/p>\n<p>Find all empty folders in the %TEMP% directory and save the paths to a text file. <br \/>.Example <br \/>PS C:\\&gt; dir $env:temp -recurse | IsEmptyFolder | Remove-Item -recurse <\/p>\n<p>Find and delete all empty folders under %TEMP%. <br \/>.Inputs <br \/>Accepts strings or directoryinfo objects as pipelined input <br \/>.Outputs <br \/>[string] <\/p>\n<p>.Link <br \/>Get-ChildItem <\/p>\n<p>.Notes <br \/>NAME: IsEmptyFolder Function <br \/>VERSION: 1.0 <br \/>AUTHOR: Jeffery Hicks <br \/>LASTEDIT: 10\/1\/2009<\/code> <code><br \/>#&gt;<\/code><\/p>\n<p><code>[CmdletBinding()]<\/code> <code><br \/>Param ( <br \/>[Parameter(ValueFromPipeline=$True, <br \/>ValueFromPipelineByPropertyName=$True, <br \/>Position=1, <br \/>Mandatory=$False, <br \/>HelpMessage=\"Enter a folder name and path.\")] <br \/>[string[]]$fullname=\".\" <br \/>) <br \/><\/code> <code>Begin { <br \/>Write-Verbose \"Starting function\" <br \/>Write-Debug \"Starting function\" <br \/>Write-Debug \"Running as $env:userdomain\\$env:username\"<\/code> <br \/><code>} #end Begin<\/code><\/p>\n<p><code>Process {<\/code><\/p>\n<p><code>Trap {<\/code> <br \/><code>Write-Warning \"Failed to find or enumerate $fullname\" <br \/>Write-Verbose \"Exception raised and caught by trap\" <br \/>Write-Debug \"Exception raised and caught by trap\" <br \/>Write-Debug $_.Exception <br \/>Continue<\/code> <br \/><code>} <\/p>\n<p>Write-Verbose \"Testing $fullname\" <br \/>Write-Debug \"Testing $fullname\"<\/code><\/p>\n<p><code>If ((dir $fullname -force -recurse -ea stop | where {-Not $_.PSIsContainer} | measure-object).Count -eq 0) { <br \/>Write-Verbose \"Writing empty folder fullname\" <br \/>Write-Debug \"Empty folder found\" <br \/>if ($_) { <br \/>Write-Debug \"Current object is a $($_.GetType())\" <br \/>} <br \/>#if a directory object was passed through the pipeline then we can use the object's full name. <br \/>if ($_ -is [System.IO.DirectoryInfo]) {<\/code> <br \/><code>write $_.Fullname <br \/>} <br \/>else { <br \/>#otherwise write the value passed as a parameter <br \/>write $fullname <br \/>} <\/p>\n<p>}<\/code> <code><br \/>} #end Process<\/code><\/p>\n<p><code>End {<\/code> <br \/><code>Write-Verbose \"Ending function\" <br \/>Write-Debug \"Ending function\"<\/code> <br \/><code>} #end End<\/code><\/p>\n<p><code>} #end function<\/code><\/p>\n<p>The function takes advantage of integrated help that you can add in PowerShell v2.0. The comment block at the beginning defines a synopis, decription, parameter usage and examples. This is terrific because all I have to do is ask for help like any other cmdlet.<\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/help_ief.png\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/zrtn_003p5cb42026_tn.jpg\" style=\"TEXT-ALIGN: center; MARGIN: 0px auto 5px; WIDTH: 400px; DISPLAY: block; HEIGHT: 198px\" height=\"198\" width=\"400\"\/><\/a><\/p>\n<p>The function is pretty straight forward. You can give it a folder name as a parameter. If the folder is empty of file, including an subfolders that might contain files, then the filename is returned.<\/p>\n<p><code>PS C:\\&gt; IsEmptyFolder C:\\test\\empty <br \/>C:\\test\\empty<\/code><\/p>\n<p>Or you can pipe directory objects to the function.This is the more common scenario I would imagine.<\/p>\n<p><code>PS C:\\&gt; dir c:\\test -recurse | where {$_.PSIsContainer} | IsEmptyFolder | Sort <br \/>C:\\test\\common files\\data b <br \/>C:\\test\\empty <br \/>C:\\test\\files <br \/>C:\\test\\foo bar <br \/>C:\\test\\foo bar\\child <br \/>C:\\test\\foo2 <br \/>C:\\test\\nada\\1\\2<\/code><\/p>\n<p>The ultimate goal would be to actually remove them.<\/p>\n<p><code>PS C:\\&gt; dir c:\\test -recurse | where {$_.PSIsContainer} | IsEmptyFolder | del -recurse -whatif <br \/>What if: Performing operation \"Remove Directory\" on Target \"C:\\test\\empty\". <br \/>What if: Performing operation \"Remove Directory\" on Target \"C:\\test\\files\". <br \/>What if: Performing operation \"Remove Directory\" on Target \"C:\\test\\foo bar\". <br \/>What if: Performing operation \"Remove Directory\" on Target \"C:\\test\\foo2\". <br \/>What if: Performing operation \"Remove Directory\" on Target \"C:\\test\\common files\\data b\". <br \/>What if: Performing operation \"Remove Directory\" on Target \"C:\\test\\foo bar\\child\". <br \/>What if: Performing operation \"Remove Directory\" on Target \"C:\\test\\nada\\1\\2\".<\/code><\/p>\n<p>As you look through the function, you'll see some <strong>Write-Verbose<\/strong> and <strong>Write-Debug<\/strong> expressions. Because I'm using [CmdletBinding()] <br \/>in the function, I can use the common parameters like -Verbose and -Debug. When these parameters are specified, the corresponding PowerShell commands are sent to the appropriate pipeline. This is a great way of adding debug or trace information into your v2 script or function from the very beginning.<\/p>\n<p><span style=\"COLOR: #ff0000\">Please test this thoroughly in a non-production environment, especially if you will be deleting anything. From my testing I think I've covered everything but if not, please let me know.<\/span><\/p>\n<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/IsEmptyFolder1.txt\" rel=\"enclosure\" title=\"IsEmptyFolder.txt ( 3.64 kB)\">Download the function<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In keeping with my recent trend of offering solutions based on PowerShell v2.0, here&#8217;s a function I&#8217;ve revised to test if a folder is empty. I can&#8217;t recall where I used the original function or if I ever did. But I came across it recently and decided to give it a facelift. Manually determining if&#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":[72,75,8],"tags":[22,97,534,540],"class_list":["post-407","post","type-post","status-publish","format-standard","hentry","category-commandline","category-powershell-v2-0","category-scripting","tag-automation","tag-filesystem","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Is That Folder Empty? &#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\/407\/is-that-folder-empty\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Is That Folder Empty? &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"In keeping with my recent trend of offering solutions based on PowerShell v2.0, here&#039;s a function I&#039;ve revised to test if a folder is empty. I can&#039;t recall where I used the original function or if I ever did. But I came across it recently and decided to give it a facelift. Manually determining if...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2009-10-01T02:07:05+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2009-10-01T13:02:40+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/zrtn_003p5cb42026_tn.jpg\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Is That Folder Empty?\",\"datePublished\":\"2009-10-01T02:07:05+00:00\",\"dateModified\":\"2009-10-01T13:02:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/\"},\"wordCount\":328,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2009\\\/09\\\/zrtn_003p5cb42026_tn.jpg\",\"keywords\":[\"Automation\",\"FileSystem\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"CommandLine\",\"PowerShell v2.0\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/\",\"name\":\"Is That Folder Empty? &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2009\\\/09\\\/zrtn_003p5cb42026_tn.jpg\",\"datePublished\":\"2009-10-01T02:07:05+00:00\",\"dateModified\":\"2009-10-01T13:02:40+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2009\\\/09\\\/zrtn_003p5cb42026_tn.jpg\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2009\\\/09\\\/zrtn_003p5cb42026_tn.jpg\",\"width\":\"400\",\"height\":\"198\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/scripting\\\/407\\\/is-that-folder-empty\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"CommandLine\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/commandline\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Is That Folder Empty?\"}]},{\"@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":"Is That Folder Empty? &#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\/407\/is-that-folder-empty\/","og_locale":"en_US","og_type":"article","og_title":"Is That Folder Empty? &#8226; The Lonely Administrator","og_description":"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 a facelift. Manually determining if...","og_url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/","og_site_name":"The Lonely Administrator","article_published_time":"2009-10-01T02:07:05+00:00","article_modified_time":"2009-10-01T13:02:40+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/zrtn_003p5cb42026_tn.jpg","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Is That Folder Empty?","datePublished":"2009-10-01T02:07:05+00:00","dateModified":"2009-10-01T13:02:40+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/"},"wordCount":328,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/zrtn_003p5cb42026_tn.jpg","keywords":["Automation","FileSystem","PowerShell","Scripting"],"articleSection":["CommandLine","PowerShell v2.0","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/","url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/","name":"Is That Folder Empty? &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/zrtn_003p5cb42026_tn.jpg","datePublished":"2009-10-01T02:07:05+00:00","dateModified":"2009-10-01T13:02:40+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/zrtn_003p5cb42026_tn.jpg","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2009\/09\/zrtn_003p5cb42026_tn.jpg","width":"400","height":"198"},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"CommandLine","item":"https:\/\/jdhitsolutions.com\/blog\/category\/commandline\/"},{"@type":"ListItem","position":2,"name":"Is That Folder Empty?"}]},{"@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":1546,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-v2-0\/1546\/get-top-level-folder-usage\/","url_meta":{"origin":407,"position":0},"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":[]},{"id":8241,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8241\/cleaning-with-powershell-revisited\/","url_meta":{"origin":407,"position":1},"title":"Cleaning with PowerShell Revisited","author":"Jeffery Hicks","date":"March 23, 2021","format":false,"excerpt":"Springtime is approaching in North America. Where I live, the snow has finally melted and we have blue skies with warmer temperatures. Of course, this means Spring Cleaning. Time to clear out the winter debris and spruce up the house. For me, this is also a good time for some\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\/03\/remove-file.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/remove-file.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/remove-file.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/remove-file.png?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":3551,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/","url_meta":{"origin":407,"position":2},"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":3014,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/3014\/getting-top-level-folder-report-in-powershell\/","url_meta":{"origin":407,"position":3},"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":2318,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2318\/introducing-the-scriptinghelp-powershell-module\/","url_meta":{"origin":407,"position":4},"title":"Introducing the ScriptingHelp PowerShell Module","author":"Jeffery Hicks","date":"May 16, 2012","format":false,"excerpt":"Over the last few weeks I've posted articles on the different parameter validation options in Windows PowerShell. More than one person suggested consolidating the articles. That seemed like a good idea. There were a variety of ways to handle this but I wanted something more PowerShell-oriented. Then I realized, why\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\/03\/helpbubble.png?resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4999,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/4999\/finding-git-repositories-with-powershell\/","url_meta":{"origin":407,"position":5},"title":"Finding Git Repositories with PowerShell","author":"Jeffery Hicks","date":"May 18, 2016","format":false,"excerpt":"As part of my ongoing improvement process this year I am starting to use Git much more. Yesterday I posted an article with my PowerShell script to create a new project folder which includes creating a Git repository. My challenge has been that I don't always remember what I have\u2026","rel":"","context":"In &quot;Git&quot;","block_context":{"text":"Git","link":"https:\/\/jdhitsolutions.com\/blog\/category\/git\/"},"img":{"alt_text":"find git repositories with PowerShell","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-1.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-1.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2016\/05\/image_thumb-1.png?resize=525%2C300 1.5x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/407","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=407"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/407\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}