{"id":3551,"date":"2013-11-11T09:47:54","date_gmt":"2013-11-11T14:47:54","guid":{"rendered":"http:\/\/jdhitsolutions.com\/blog\/?p=3551"},"modified":"2013-11-11T09:47:54","modified_gmt":"2013-11-11T14:47:54","slug":"powershell-clean-up-tools","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/","title":{"rendered":"PowerShell Clean Up Tools"},"content":{"rendered":"<p><a href=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/021913_2047_WordTest1.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-2802\" alt=\"021913_2047_WordTest1.png\" src=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/021913_2047_WordTest1.png\" width=\"144\" height=\"109\" \/><\/a>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 periodically to clean out my temp folders. I should probably set them up as a scheduled job to run monthly, but I haven't gotten around to that yet. In the mean time, let me show you what I have.<\/p>\n<p>First, I have a function to delete files from a directory that were last modified after a given date.  <\/p>\n<pre class=\"lang:ps decode:true \" >#requires -version 3.0\r\n\r\nFunction Remove-File {\r\n\r\n&lt;#\r\n.SYNOPSIS\r\nDelete files based on file age.\r\n.DESCRIPTION\r\nThis function will go start at a specified path and delete files and folders that are older than a \r\nspecified date and time. The comparison is made to the file's last modified time. The last access time\r\ndoesn't always accurately reflect when a file was last used. Typically you will use this function to\r\nclean out temp folders.\r\n.PARAMETER Path\r\nThe folder path to search. The default is the temp folder.\r\n.PARAMETER Cutoff\r\nThe date time threshold\r\n.PARAMETER Recurse\r\nRecursively search from the starting path.\r\n.PARAMETER Hidden\r\nInclude hidden and system files files.\r\n\r\n.EXAMPLE\r\nPS C:\\&gt; Remove-File -recurse -cutoff (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime -whatif\r\nRemove all files in the temp folder that are older than the computer's startup time.\r\n.EXAMPLE\r\nPS C:\\&gt; \"C:\\work\",\"$env:temp\",\"$env:windir\\temp\" | Remove-File -cutoff (Get-Date).AddDays(-30) -recurse -hidden\r\nThis command will search the 3 specified paths for all files that haven't been modified in 30 days and delete them.\r\n.NOTES\r\nNAME        :  Remove-File\r\nVERSION     :  3.0   \r\nLAST UPDATED:  11\/11\/2013\r\nAUTHOR      :  Jeffery Hicks\r\n.LINK\r\nhttp:\/\/jdhitsolutions.com\/blog\/2013\/11\/powershell-clean-up-tools\r\n.LINK\r\nGet-ChildItem \r\nRemove-Item \r\n.INPUTS\r\nString\r\n.OUTPUTS\r\nNone\r\n#&gt;\r\n\r\n[cmdletbinding(SupportsShouldProcess)]\r\n\r\nParam(\r\n[Parameter(Position=0)]\r\n[ValidateScript({Test-Path $_})]\r\n[string]$Path=$env:temp,\r\n[Parameter(Position=1,Mandatory,\r\nHelpMessage= \"Enter a cutoff date. All files after this date will be removed.\")]\r\n[ValidateScript({$_ -lt (Get-Date)})]\r\n[datetime]$Cutoff,\r\n[Switch]$Recurse,\r\n[Switch]$Hidden\r\n)\r\n    \r\nWrite-Host \"Removing files in $path older than $cutoff\" -foregroundcolor CYAN\r\n\r\n#create a hashtable of parameters to splat to Get-ChildItem\r\n$paramHash=@{\r\n Path= $Path\r\n ErrorAction= \"Stop\"\r\n File= $True\r\n}        \r\n\r\n#add optional parameters    \r\nif ($Recurse) {\r\n  $paramHash.Add(\"Recurse\",$True)\r\n}\r\n    \r\nif ($Hidden) {\r\n  $paramHash.Add(\"Force\",$True)\r\n}\r\n    \r\nTry {\r\n $files = Get-ChildItem @paramhash | where {$_.lastwritetime -lt $cutoff}\r\n }\r\nCatch {\r\n Write-Warning \"Failed to enumerate files in $path\"\r\n Write-Warning $_.Exception.Message\r\n #Bail out\r\n Return\r\n}\r\n\r\nif ($files) {\r\n#only remove files if anything was found\r\n$files| Remove-Item -Force\r\n    \r\n$stats= $files | Measure-Object -Sum length\r\n$msg=\"Attempted to delete {0} files for a total of {1} MB ({2} bytes)\" -f $stats.count,($stats.sum\/1MB -as [int]),$stats.sum  \r\nWrite-Host $msg -foregroundcolor CYAN\r\n\r\n} #if $files\r\nelse {\r\n    Write-Host \"No files found to remove\" -ForegroundColor Yellow\r\n}\r\n\r\n} #close function\r\n<\/pre>\n<p>The function supports -WhatIf so that if I run it, Remove-Item will only show me what it would delete. I use a hashtable to build a set of parameters to splat to Get-ChildItem. I love this technique for building dynamic commands. I use this command on my temp folders to delete files older than the last time the computer booted. My assumption is that anything in TEMP older than the last boot time is fair game for deletion.<\/p>\n<p>If you look at this function, you'll notice that it only affects files.  It leaves folder alone. I suppose I could modify it to remove old folders as well, but there's a chance the folder might have a newer file somewhere in the hierarchy that shouldn't be deleted so I decided to simply focus on old files. To clean up folders, I use this:<\/p>\n<pre class=\"lang:ps decode:true \" >#requires -version 3.0\r\n\r\n#remove directories that have no files.\r\n&lt;#\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#&gt;\r\nFunction Remove-EmptyFolder {\r\n\r\n[cmdletbinding(SupportsShouldProcess)]\r\n\r\nParam(\r\n[Parameter(Position=0,Mandatory,HelpMessage=\"Enter a root directory path\")]\r\n[ValidateScript({Test-Path $_})]\r\n[string]$Path=$env:temp\r\n)\r\n\r\nWrite-Host \"Removing empty folders in $Path\" -ForegroundColor Cyan\r\n\r\n#get top level folders\r\n$Folders = Get-ChildItem -Path $path -Directory -Force\r\n\r\n#test each folder for any files\r\nforeach ($folder in $folders) {\r\n  If (-NOT ($folder | dir -file -Recurse)) {\r\n   Write-Host \"Removing $($folder.FullName)\" -ForegroundColor Red\r\n   $folder | Remove-Item -Force -Recurse\r\n  }\r\n\r\n} #end foreach\r\n\r\n} #end Remove-EmptyFolder\r\n<\/pre>\n<p>This command looks for empty folders, or more precisely folders with no files. The function gets all of the top-level folders in the specified path and then searches each folder recursively for any files. If no files are found, the folder is removed.<\/p>\n<p>The two tools are great on their own. To put them to use, I created a small script.<\/p>\n<pre class=\"lang:ps decode:true \" >#requires -version 3.0\r\n\r\n&lt;#\r\n  CleanTemp.ps1\r\n  ****************************************************************\r\n  * DO NOT USE IN A PRODUCTION ENVIRONMENT UNTIL YOU HAVE TESTED *\r\n  * THOROUGHLY IN A LAB SETTING. USE AT YOUR OWN RISK.           * \t\t\t\t\t\t  * \r\n  ****************************************************************\r\n#&gt;\r\n\r\n#dot source functions\r\n. C:\\scripts\\Remove-EmptyFolder.ps1\r\n. C:\\scripts\\Remove-File3.ps1\r\n\r\n#get last boot up time.\r\n#Get-CIMInstance will return LastBootUpTime as a datetime object. No converting required.\r\n$bootTime = (Get-CimInstance -ClassName Win32_OperatingSystem).LastBootUpTime\r\n\r\n#delete files in temp folders older than the last bootup time\r\nRemove-File $env:temp $boottime -recurse -hidden\r\nRemove-File D:\\Temp $boottime -recurse -hidden \r\n\r\nWrite-Host \"Removing empty folders\" -ForegroundColor Cyan\r\nRemove-EmptyFolder $env:temp\r\nRemove-EmptyFolder D:\\temp\r\n<\/pre>\n<p>I think of the script as a \"canned\" PowerShell session. Instead of my typing the commands to clean up a few folders, I simply run the script. I inserted some Write-Host commands so I could know what the script was doing. I clean out all the old files first and then make a second pass to delete any empty folders. I trust it goes without saying that if you want to use these, you have to test in a non-production environment.<\/p>\n<p>Enjoy.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 periodically to clean out my&#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":"New from the blog: #PowerShell Clean Up Tools","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":[359],"tags":[224,137,534,445,540],"class_list":["post-3551","post","type-post","status-publish","format-standard","hentry","category-powershell-3-0","tag-function","tag-get-childitem","tag-powershell","tag-remove-item","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>PowerShell Clean Up Tools &#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-3-0\/3551\/powershell-clean-up-tools\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"PowerShell Clean Up Tools &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"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 periodically to clean out my...\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2013-11-11T14:47:54+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/021913_2047_WordTest1.png\" \/>\n<meta name=\"author\" content=\"Jeffery Hicks\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:site\" content=\"@JeffHicks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Jeffery Hicks\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"PowerShell Clean Up Tools\",\"datePublished\":\"2013-11-11T14:47:54+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/\"},\"wordCount\":400,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/02\\\/021913_2047_WordTest1.png\",\"keywords\":[\"Function\",\"Get-ChildItem\",\"PowerShell\",\"Remove-Item\",\"Scripting\"],\"articleSection\":[\"Powershell 3.0\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/\",\"name\":\"PowerShell Clean Up Tools &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/#primaryimage\"},\"thumbnailUrl\":\"http:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/02\\\/021913_2047_WordTest1.png\",\"datePublished\":\"2013-11-11T14:47:54+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/02\\\/021913_2047_WordTest1.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2013\\\/02\\\/021913_2047_WordTest1.png\",\"width\":144,\"height\":109},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell-3-0\\\/3551\\\/powershell-clean-up-tools\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Powershell 3.0\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell-3-0\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PowerShell Clean Up Tools\"}]},{\"@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":"PowerShell Clean Up Tools &#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-3-0\/3551\/powershell-clean-up-tools\/","og_locale":"en_US","og_type":"article","og_title":"PowerShell Clean Up Tools &#8226; The Lonely Administrator","og_description":"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 periodically to clean out my...","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/","og_site_name":"The Lonely Administrator","article_published_time":"2013-11-11T14:47:54+00:00","og_image":[{"url":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/021913_2047_WordTest1.png","type":"","width":"","height":""}],"author":"Jeffery Hicks","twitter_card":"summary_large_image","twitter_creator":"@JeffHicks","twitter_site":"@JeffHicks","twitter_misc":{"Written by":"Jeffery Hicks","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"PowerShell Clean Up Tools","datePublished":"2013-11-11T14:47:54+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/"},"wordCount":400,"commentCount":2,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/021913_2047_WordTest1.png","keywords":["Function","Get-ChildItem","PowerShell","Remove-Item","Scripting"],"articleSection":["Powershell 3.0"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/","name":"PowerShell Clean Up Tools &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/#primaryimage"},"thumbnailUrl":"http:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/021913_2047_WordTest1.png","datePublished":"2013-11-11T14:47:54+00:00","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/021913_2047_WordTest1.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/02\/021913_2047_WordTest1.png","width":144,"height":109},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell-3-0\/3551\/powershell-clean-up-tools\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Powershell 3.0","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell-3-0\/"},{"@type":"ListItem","position":2,"name":"PowerShell Clean Up Tools"}]},{"@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":8241,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8241\/cleaning-with-powershell-revisited\/","url_meta":{"origin":3551,"position":0},"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":2900,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2900\/test-hyper-v-vhd-folders-with-powershell\/","url_meta":{"origin":3551,"position":1},"title":"Test Hyper-V VHD Folders with PowerShell","author":"Jeffery Hicks","date":"April 1, 2013","format":false,"excerpt":"I've recently added a USB 3.0 Express Card adapter to my laptop to provide USB 3.0 functionality. The added performance is very useful in my Hyper-V setup. However, I am running into a glitch that I have yet to figure out where the external drives (the Express card has 2\u2026","rel":"","context":"In &quot;Hyper-V&quot;","block_context":{"text":"Hyper-V","link":"https:\/\/jdhitsolutions.com\/blog\/category\/hyper-v\/"},"img":{"alt_text":"test-vhdpath","src":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/test-vhdpath-1024x314.png?resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/test-vhdpath-1024x314.png?resize=350%2C200 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2013\/04\/test-vhdpath-1024x314.png?resize=525%2C300 1.5x"},"classes":[]},{"id":407,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/407\/is-that-folder-empty\/","url_meta":{"origin":3551,"position":2},"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":2390,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/2390\/get-acl-information-with-powershell\/","url_meta":{"origin":3551,"position":3},"title":"Get ACL Information with PowerShell","author":"Jeffery Hicks","date":"June 21, 2012","format":false,"excerpt":"I got a question in the \"Ask Don and Jeff\" forum on PowerShell.com that intrigued me. The issue was working with the results of the Get-ACL cmdlet. The resulting object includes a property called Access which is a collection of access rule objects. Assuming you are using this with the\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\/2012\/06\/get-aclinfo-1-300x77.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":3551,"position":4},"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":2673,"url":"https:\/\/jdhitsolutions.com\/blog\/scripting\/2673\/friday-fun-edit-recent-file\/","url_meta":{"origin":3551,"position":5},"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":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3551","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=3551"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/3551\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=3551"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=3551"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=3551"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}