{"id":7024,"date":"2019-12-03T10:55:00","date_gmt":"2019-12-03T15:55:00","guid":{"rendered":"https:\/\/jdhitsolutions.com\/blog\/?p=7024"},"modified":"2019-12-02T10:59:13","modified_gmt":"2019-12-02T15:59:13","slug":"managing-the-recycle-bin-with-powershell","status":"publish","type":"post","link":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/","title":{"rendered":"Managing the Recycle Bin with PowerShell"},"content":{"rendered":"<p>A while ago, I posted <a title=\"Read the challenge\" href=\"https:\/\/ironscripter.us\/raise-the-dead-with-this-powershell-challenge\/\" target=\"_blank\" rel=\"noopener noreferrer\">an Iron Scripter challenge<\/a> asking you to write some PowerShell code for working with items in the recycle bin. You were asked to calculate how much space the recycle bin is using and then restore a file. If you'd prefer, stop reading this post, check out the challenge and see what you can come up with.\u00a0 If you get stuck, this article might get you back on track. Although, I'm sure there are several ways to meet the challenge. My solution is far from the only solution.<\/p>\n<h2>Parsing the Recycle Bin<\/h2>\n<p>I decided to use the COM object approach and used a reference to Shell.Application. The Windows Recycle Bin can be accessed as Namespace 10.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$shell = New-Object -com shell.application\n$rb = $shell.Namespace(10)\n<\/pre>\n<p>This namespace will include the recycle bin on all fixed disks. Even though this object type may not be well documented, you can still use PowerShell to discover what to do. <a title=\"Read online help for this command\" href=\"http:\/\/go.microsoft.com\/fwlink\/?LinkID=113322\" target=\"_blank\" rel=\"noopener noreferrer\">Get-Member<\/a> is still your friend.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"The Recycle Bin COM object\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb.png\" alt=\"The Recycle Bin COM object\" width=\"1028\" height=\"527\" border=\"0\" \/><\/a><\/p>\n<p>The Items property looks like it will give me deleted items.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-1.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Exploring the Recycle Bin with PowerShell\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-1.png\" alt=\"Exploring the Recycle Bin with PowerShell\" width=\"1028\" height=\"629\" border=\"0\" \/><\/a><\/p>\n<p>And sure enough it does. To make this easier, I'll add the items to an array.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-2.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Recycle Bin items\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-2.png\" alt=\"Recycle Bin items\" width=\"1028\" height=\"507\" border=\"0\" \/><\/a><\/p>\n<p>This is where it gets tricky.<\/p>\n<p>Even though it looks like there are only 156 items in my recycle bin, there are many more. I only see the top level 156 items.\u00a0 Items that are folders have their own Items property.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-3.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Getting Recycle Bin child items\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-3.png\" alt=\"Getting Recycle Bin child items\" width=\"1028\" height=\"334\" border=\"0\" \/><\/a><\/p>\n<p>As you can see, there is good information for each deleted file. In exploring objects with Get-Member, I put together a function to turn each deleted item into a usable PowerShell object.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">Function ParseItem {\n    [cmdletbinding()]\n    Param(\n        [Parameter(Mandatory, ValueFromPipeline)]\n        [object]$Item\n    )\n    #this function relies variables set in a parent scope\n    Process {\n        Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] Processing $($item.path)\"\n        \n        # uncomment for troubleshooting\n        # $global:raw += $item\n        if ($item.IsFolder -AND ($item.type -notmatch \"ZIP\")) {\n            Write-Verbose \"Enumerating $($item.name)\"\n            Try {\n                #track the path name through each child object\n                if ($fldpath) {\n                    $fldpath = Join-Path -Path $fldPath -ChildPath $item.GetFolder.Title\n                }\n                else {\n                    $fldPath = $item.GetFolder.Title\n                }\n                #recurse through child items\n                $item.GetFolder().Items() | ParseItem\n                Remove-Variable -Name fldpath\n            }\n            Catch {\n               # Uncomment for troubleshooting\n               # $global:rbwarn += $item\n                Write-Warning ($item | Out-String)\n                Write-Warning $_.exception.message\n            }\n        }\n        else {\n            #sometimes the original location is stored in an extended property\n            $data = $item.ExtendedProperty(\"infotip\").split(\"`n\") | Where-Object { $_ -match \"Original location\" }\n            if ($data) {\n                $origPath = $data.split(\":\", 2)[1].trim()\n                $full = Join-Path -path $origPath -ChildPath $item.name -ErrorAction stop\n                Remove-Variable -Name data\n            }\n            else {\n                #no extended property so use this code to attemp to rebuild the original location\n                if ($item.parent.title -match \"^[C-Zc-z]:\\\\\") {\n                    $origPath = $item.parent.title\n                }\n                elseif ($fldpath) {\n                    $origPath = $fldPath\n                }\n                else {\n                    $test = $item.parent\n                    Write-Host \"searching for parent on $($test.self.path)\" -ForegroundColor cyan\n                    do { $test = $test.parentfolder; $save = $test.title } until ($test.title -match \"^[C-Zc-z]:\\\\\" -OR $test.title -eq $save)\n                    $origPath = $test.title\n                }\n\n                $full = Join-Path -path $origPath -ChildPath $item.name -ErrorAction stop\n            }\n\n            [pscustomobject]@{\n                PSTypename       = \"DeletedItem\"\n                Name             = $item.name\n                Path             = $item.Path\n                Modified         = $item.ModifyDate\n                OriginalPath     = $origPath\n                OriginalFullName = $full\n                Size             = $item.Size\n                IsFolder         = $item.IsFolder\n                Type             = $item.Type\n            }\n        }\n    } #process\n}\n<\/pre>\n<p>My function has a non-standard name because I am using it as an internal, helper function inside of a control script. I can use this function to transform each recycle bin item into something easier to work with.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-4.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"My parsed Recycle Bin object\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-4.png\" alt=\"My parsed Recycle Bin object\" width=\"1028\" height=\"229\" border=\"0\" \/><\/a><\/p>\n<p>This means I can get all the items like this:<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$bin = $rb.items() | ParseItem\n<\/pre>\n<p>Which makes it very easy to calculate how much space my recycle bin is using.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-5.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Measuring the Recycle Bin with PowerShell\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-5.png\" alt=\"Measuring the Recycle Bin with PowerShell\" width=\"1028\" height=\"166\" border=\"0\" \/><\/a><\/p>\n<p>With this code as my foundation, it wouldn't be that much more work to get Recycle Bin information for different fixed drives.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">$bin | group-object -Property {$_.path.substring(0,2)} |\nSelect-Object -Property Name,Count,\n@{Name=\"SizeMB\";Expression = {($_.group | measure-object -Property size -sum).sum\/1MB}}\n<\/pre>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-6.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Recycle Bin usage by drive\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-6.png\" alt=\"Recycle Bin usage by drive\" width=\"505\" height=\"187\" border=\"0\" \/><\/a><\/p>\n<h2>Restoring a Recycle Bin Item<\/h2>\n<p>Because I did all the work up front to write an object to the pipeline with original location information, it was pretty easy to write a function to restore the deleted item by moving it from the recycle bin location to the original location.<\/p>\n<pre class=\"lang:ps mark:0 decode:true\">Function Restore-RecycleBinItem {\n    [cmdletbinding(SupportsShouldProcess)]\n    Param(\n        [Parameter(Mandatory, ValueFromPipeline)]\n        [ValidateNotNullOrEmpty()]\n        [object]$Item\n    )\n    Begin {\n        Write-Verbose \"[$((Get-Date).TimeofDay) BEGIN  ] Starting $($myinvocation.mycommand)\"\n\n    } #begin\n\n    Process {\n        Write-Verbose \"[$((Get-Date).TimeofDay) PROCESS] $($Item.Path) \"\n        if (-Not (Test-Path $Item.originalPath)) {\n            New-Item $Item.originalpath -force -itemtype directory\n        }\n        Move-Item -path $Item.Path -Destination $Item.OriginalFullName -PassThru -Force\n\n    } #process\n\n    End {\n        Write-Verbose \"[$((Get-Date).TimeofDay) END    ] Ending $($myinvocation.mycommand)\"\n    } #end\n\n} #close Restore-RecyleBinItem\n<\/pre>\n<p>Now it is very simple to restore a deleted item.<\/p>\n<p><a href=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image-7.png\"><img loading=\"lazy\" decoding=\"async\" style=\"display: inline; background-image: none;\" title=\"Restoring a deleted item\" src=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb-7.png\" alt=\"Restoring a deleted item\" width=\"1028\" height=\"609\" border=\"0\" \/><\/a><\/p>\n<p>I should probably revise the restore function to let me specify an alternate location. Or add some logic not to overwrite an existing file. But I can leave those scripting challenges to you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A while ago, I posted an Iron Scripter challenge asking you to write some PowerShell code for working with items in the recycle bin. You were asked to calculate how much space the recycle bin is using and then restore a file. If you&#8217;d prefer, stop reading this post, check out the challenge and see&#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 on the blog: Managing the Recycle Bin with #PowerShell - An #IronScripter Solution","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":[4,8],"tags":[423,618,534,540],"class_list":["post-7024","post","type-post","status-publish","format-standard","hentry","category-powershell","category-scripting","tag-com","tag-iron-scripter","tag-powershell","tag-scripting"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Managing the Recycle Bin with PowerShell &#8226; The Lonely Administrator<\/title>\n<meta name=\"description\" content=\"My ideas for the Iron Scripter PowerShell challenge to work with the Windows 10 Recycle Bin. Definitely advanced stuff but some good scripting techniques.\" \/>\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\/7024\/managing-the-recycle-bin-with-powershell\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Managing the Recycle Bin with PowerShell &#8226; The Lonely Administrator\" \/>\n<meta property=\"og:description\" content=\"My ideas for the Iron Scripter PowerShell challenge to work with the Windows 10 Recycle Bin. Definitely advanced stuff but some good scripting techniques.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/\" \/>\n<meta property=\"og:site_name\" content=\"The Lonely Administrator\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-03T15:55:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb.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=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/\"},\"author\":{\"name\":\"Jeffery Hicks\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"headline\":\"Managing the Recycle Bin with PowerShell\",\"datePublished\":\"2019-12-03T15:55:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/\"},\"wordCount\":441,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/image_thumb.png\",\"keywords\":[\"COM\",\"Iron Scripter\",\"PowerShell\",\"Scripting\"],\"articleSection\":[\"PowerShell\",\"Scripting\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/\",\"name\":\"Managing the Recycle Bin with PowerShell &#8226; The Lonely Administrator\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/image_thumb.png\",\"datePublished\":\"2019-12-03T15:55:00+00:00\",\"description\":\"My ideas for the Iron Scripter PowerShell challenge to work with the Windows 10 Recycle Bin. Definitely advanced stuff but some good scripting techniques.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/#primaryimage\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/image_thumb.png\",\"contentUrl\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/12\\\/image_thumb.png\",\"width\":1028,\"height\":527},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/powershell\\\/7024\\\/managing-the-recycle-bin-with-powershell\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"PowerShell\",\"item\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/category\\\/powershell\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Managing the Recycle Bin with PowerShell\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/\",\"name\":\"The Lonely Administrator\",\"description\":\"Practical Advice for the Automating IT Pro\",\"publisher\":{\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/jdhitsolutions.com\\\/blog\\\/#\\\/schema\\\/person\\\/d0258030b41f07fd745f4078bdf5b6c9\",\"name\":\"Jeffery Hicks\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\",\"caption\":\"Jeffery Hicks\"},\"logo\":{\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Managing the Recycle Bin with PowerShell &#8226; The Lonely Administrator","description":"My ideas for the Iron Scripter PowerShell challenge to work with the Windows 10 Recycle Bin. Definitely advanced stuff but some good scripting techniques.","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\/7024\/managing-the-recycle-bin-with-powershell\/","og_locale":"en_US","og_type":"article","og_title":"Managing the Recycle Bin with PowerShell &#8226; The Lonely Administrator","og_description":"My ideas for the Iron Scripter PowerShell challenge to work with the Windows 10 Recycle Bin. Definitely advanced stuff but some good scripting techniques.","og_url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/","og_site_name":"The Lonely Administrator","article_published_time":"2019-12-03T15:55:00+00:00","og_image":[{"url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb.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":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/#article","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/"},"author":{"name":"Jeffery Hicks","@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"headline":"Managing the Recycle Bin with PowerShell","datePublished":"2019-12-03T15:55:00+00:00","mainEntityOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/"},"wordCount":441,"commentCount":0,"publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb.png","keywords":["COM","Iron Scripter","PowerShell","Scripting"],"articleSection":["PowerShell","Scripting"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/","url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/","name":"Managing the Recycle Bin with PowerShell &#8226; The Lonely Administrator","isPartOf":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/#primaryimage"},"image":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/#primaryimage"},"thumbnailUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb.png","datePublished":"2019-12-03T15:55:00+00:00","description":"My ideas for the Iron Scripter PowerShell challenge to work with the Windows 10 Recycle Bin. Definitely advanced stuff but some good scripting techniques.","breadcrumb":{"@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/#primaryimage","url":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb.png","contentUrl":"https:\/\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2019\/12\/image_thumb.png","width":1028,"height":527},{"@type":"BreadcrumbList","@id":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7024\/managing-the-recycle-bin-with-powershell\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"PowerShell","item":"https:\/\/jdhitsolutions.com\/blog\/category\/powershell\/"},{"@type":"ListItem","position":2,"name":"Managing the Recycle Bin with PowerShell"}]},{"@type":"WebSite","@id":"https:\/\/jdhitsolutions.com\/blog\/#website","url":"https:\/\/jdhitsolutions.com\/blog\/","name":"The Lonely Administrator","description":"Practical Advice for the Automating IT Pro","publisher":{"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jdhitsolutions.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/jdhitsolutions.com\/blog\/#\/schema\/person\/d0258030b41f07fd745f4078bdf5b6c9","name":"Jeffery Hicks","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg","caption":"Jeffery Hicks"},"logo":{"@id":"https:\/\/secure.gravatar.com\/avatar\/832ae5d438fdcfc1420d720cd1991307927de8a0b12f2342e81c30f773e21098?s=96&d=wavatar&r=pg"}}]}},"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_likes_enabled":true,"jetpack-related-posts":[{"id":8107,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8107\/scripting-challenge-meetup\/","url_meta":{"origin":7024,"position":0},"title":"Scripting Challenge Meetup","author":"Jeffery Hicks","date":"February 1, 2021","format":false,"excerpt":"As you probably know, I am the PowerShell problem master behind the challenges from the Iron Scripter site. Solving a PowerShell scripting challenge is a great way to test your skills and expand your knowledge. The final result is merely a means to an end. How you get there and\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\/02\/rubik.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":9018,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/9018\/an-iron-scripter-warm-up-solution\/","url_meta":{"origin":7024,"position":1},"title":"An Iron Scripter Warm-Up Solution","author":"Jeffery Hicks","date":"May 6, 2022","format":false,"excerpt":"We just wrapped up the 2022 edition of the PowerShell+DevOps Global Summit. It was terrific to be with passionate PowerShell professionals again. The culmination of the event is the Iron Scripter Challenge. You can learn more about this year's event and winner here. But there is more to the Iron\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":7489,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7489\/powershell-word-play\/","url_meta":{"origin":7024,"position":2},"title":"PowerShell Word Play","author":"Jeffery Hicks","date":"May 19, 2020","format":false,"excerpt":"A few weeks ago an Iron Scripter PowerShell challenge was issued that involved playing with words and characters. Remember, the Iron Scripter challenges aren't intended to create meaningful, production worthy code. They are designed to help you learn PowerShell fundamentals and scripting techniques. This particular challenge was aimed at beginner\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\/05\/doublechar.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/05\/doublechar.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":7559,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7559\/an-expanded-powershell-scripting-inventory-tool\/","url_meta":{"origin":7024,"position":3},"title":"An Expanded PowerShell Scripting Inventory Tool","author":"Jeffery Hicks","date":"June 19, 2020","format":false,"excerpt":"The other day I shared my code that I worked up to solve an Iron Scripter PowerShell challenge. One of the shortcomings was that I didn't address a challenge to include a property that would indicate what file was using a given command. I also felt I could do better\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\/06\/get-psscriptinventory.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=700%2C400&ssl=1 2x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=1050%2C600&ssl=1 3x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/06\/get-psscriptinventory.png?resize=1400%2C800&ssl=1 4x"},"classes":[]},{"id":8236,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/8236\/solving-another-powershell-math-challenge\/","url_meta":{"origin":7024,"position":4},"title":"Solving Another PowerShell Math Challenge","author":"Jeffery Hicks","date":"March 22, 2021","format":false,"excerpt":"Last month, the Iron Scripter Chairman posted a \"fun\" PowerShell scripting challenge. Actually, a few math-related challenges . As with all these challenges, the techniques and concepts you use to solve the challenge are more important than the result itself. Here's how I approached the problems. Problem #1 The first\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\/get-possiblesum.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2021\/03\/get-possiblesum.png?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":7680,"url":"https:\/\/jdhitsolutions.com\/blog\/powershell\/7680\/friday-fun-back-to-school-with-powershell\/","url_meta":{"origin":7024,"position":5},"title":"Friday Fun: Back to School with PowerShell","author":"Jeffery Hicks","date":"September 11, 2020","format":false,"excerpt":"For today's fun with PowerShell, I thought I'd share my solutions for a recent Iron Scripter challenge. If you aren't familiar with these challenges, and you should be, they are designed to test your PowerShell skills and hopefully help you learn something new. There are challenges for all skill levels\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\/2020\/09\/get-cylindervolume-format.png?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-cylindervolume-format.png?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-cylindervolume-format.png?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/jdhitsolutions.com\/blog\/wp-content\/uploads\/2020\/09\/get-cylindervolume-format.png?resize=700%2C400&ssl=1 2x"},"classes":[]}],"_links":{"self":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7024","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=7024"}],"version-history":[{"count":0,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/7024\/revisions"}],"wp:attachment":[{"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=7024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=7024"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jdhitsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=7024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}