<\/blockquote>\nI would try<\/p>\n
Get-ChildItem \"F:\\Home\\userabc\\My Documents\\$RECYCLE.BIN\" | Remove-Item -recurse\n<\/code><\/pre>\nYou don’t need the “*”, you’re already getting the child items from that folder. I could be wrong, but I think that’s what’s preventing it from working just from a glance.<\/p>","upvoteCount":2,"datePublished":"2019-08-27T09:28:32.000Z","url":"https://community.spiceworks.com/t/emptying-recycle-bin-in-multiple-locations/727375/2","author":{"@type":"Person","name":"Jrx1216","url":"https://community.spiceworks.com/u/Jrx1216"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Jrx1216:<\/div>\n
\n<\/blockquote>\nI would try<\/p>\n
Get-ChildItem \"F:\\Home\\userabc\\My Documents\\$RECYCLE.BIN\" | Remove-Item -recurse\n<\/code><\/pre>\nYou don’t need the “*”, you’re already getting the child items from that folder. I could be wrong, but I think that’s what’s preventing it from working just from a glance.<\/p>\n<\/blockquote>\n<\/aside>\n
Ah, I realize now that I had an extra “*”- “F:\\Home\\userabc\\My Documents$RECYCLE.BIN__*__”<\/p>\n
I ran it without it and still get the below<\/p>\n
Cannot find path 'F:\\Home\\userabc\\My Documents\\.BIN' because it does not exist\n<\/code><\/pre>\nYou’ll note it’s barking because the $RECYCLE, is this due to the “$RECYCLE” somehow throwing the script off?<\/p>","upvoteCount":1,"datePublished":"2019-08-27T09:33:15.000Z","url":"https://community.spiceworks.com/t/emptying-recycle-bin-in-multiple-locations/727375/3","author":{"@type":"Person","name":"bsod","url":"https://community.spiceworks.com/u/bsod"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Jrx1216:<\/div>\n
\n\n\n
<\/div>\n
BSOD'D:<\/div>\n
\n\n\n
<\/div>\n
Jrx1216:<\/div>\n
\n<\/blockquote>\nI would try<\/p>\n
Get-ChildItem \"F:\\Home\\userabc\\My Documents\\$RECYCLE.BIN\" | Remove-Item -recurse\n<\/code><\/pre>\nYou don’t need the “*”, you’re already getting the child items from that folder. I could be wrong, but I think that’s what’s preventing it from working just from a glance.<\/p>\n<\/blockquote>\n<\/aside>\n
Ah, I realize now that I had an extra “*”- “F:\\Home\\userabc\\My Documents$RECYCLE.BIN__*__”<\/p>\n
I ran it without it and still get the below<\/p>\n
Cannot find path 'F:\\Home\\userabc\\My Documents\\.BIN' because it does not exist\n<\/code><\/pre>\nYou’ll note it’s barking because the $RECYCLE, is this due to the “$RECYCLE” somehow throwing the script off?<\/p>\n<\/blockquote>\n<\/aside>\n
Ah, yeah, that would do it. You should enclose it in literal quotes (’ - single quotes mean literal)<\/p>\n
Get-ChildItem 'F:\\Home\\userabc\\My Documents\\$RECYCLE.BIN' | Remove-Item -recurse\n<\/code><\/pre>\nThe other option is to escape the $ with the ` grave key<\/p>\n
Get-ChildItem \"F:\\Home\\userabc\\My Documents\\`$RECYCLE.BIN\" | Remove-Item -recurse\n<\/code><\/pre>\nI think one of those may work.<\/p>\n<\/blockquote>\n<\/aside>\n
So the script no longer errors, but it’s not deleting the files within the $RECYCLE.BIN for the user. Tried with the -force switch too<\/p>","upvoteCount":1,"datePublished":"2019-08-27T09:43:20.000Z","url":"https://community.spiceworks.com/t/emptying-recycle-bin-in-multiple-locations/727375/5","author":{"@type":"Person","name":"bsod","url":"https://community.spiceworks.com/u/bsod"}},{"@type":"Answer","text":"
Unless you use the -Force parameter I don’t believe Get-ChildItem returns hidden items (which is both the bins and the items within the bins). If you want to empty all of them see if this works:<\/p>\n
$RecycleBins = Get-ChildItem -Path 'D:' -Filter '$RECYCLE.BIN' -Recurse -Force | Where {$_.PSIsContainer}\nForEach ($Bin in $RecycleBins) {Get-ChildItem -Path $Bin.FullName -Force | Remove-Item -Force -Recurse}\n<\/code><\/pre>","upvoteCount":2,"datePublished":"2019-08-27T09:54:47.000Z","url":"https://community.spiceworks.com/t/emptying-recycle-bin-in-multiple-locations/727375/6","author":{"@type":"Person","name":"francishagyard2","url":"https://community.spiceworks.com/u/francishagyard2"}},{"@type":"Answer","text":"\n\n
<\/div>\n
francishagyard2:<\/div>\n
\nUnless you use the -Force parameter I don’t believe Get-ChildItem returns hidden items (which is both the bins and the items within the bins). If you want to empty all of them see if this works:<\/p>\n
$RecycleBins = Get-ChildItem -Path 'D:' -Filter '$RECYCLE.BIN' -Recurse -Force | Where {$_.PSIsContainer}\nForEach ($Bin in $RecycleBins) {Get-ChildItem -Path $Bin.FullName -Force | Remove-Item -Force -Recurse}\n<\/code><\/pre>\n<\/blockquote>\n<\/aside>\nIf I want to go with small steps first, instead of whole hog, will the below work for one user? Taking into account, I only want to delete from the $RECYCLE.BIN and nothing else<\/p>\n
$RecycleBins = Get-ChildItem -Path 'F:\\Home\\userabc\\My Documents\\' -Filter '$RECYCLE.BIN' -Recurse -Force | Where {$_.PSIsContainer}\nForEach ($Bin in $RecycleBins) {Get-ChildItem -Path $Bin.FullName -Force | Remove-Item -Force -Recurse}\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2019-08-27T10:09:53.000Z","url":"https://community.spiceworks.com/t/emptying-recycle-bin-in-multiple-locations/727375/7","author":{"@type":"Person","name":"bsod","url":"https://community.spiceworks.com/u/bsod"}},{"@type":"Answer","text":"\n\n
<\/div>\n
BSOD'D:<\/div>\n
\n\n\n
<\/div>\n
Jrx1216:<\/div>\n
\n\n\n
<\/div>\n
BSOD'D:<\/div>\n
\n\n\n
<\/div>\n
Jrx1216:<\/div>\n
\n<\/blockquote>\nI would try<\/p>\n
Get-ChildItem \"F:\\Home\\userabc\\My Documents\\$RECYCLE.BIN\" | Remove-Item -recurse\n<\/code><\/pre>\nYou don’t need the “*”, you’re already getting the child items from that folder. I could be wrong, but I think that’s what’s preventing it from working just from a glance.<\/p>\n<\/blockquote>\n<\/aside>\n
Ah, I realize now that I had an extra “*”- “F:\\Home\\userabc\\My Documents$RECYCLE.BIN__*__”<\/p>\n
I ran it without it and still get the below<\/p>\n
Cannot find path 'F:\\Home\\userabc\\My Documents\\.BIN' because it does not exist\n<\/code><\/pre>\nYou’ll note it’s barking because the $RECYCLE, is this due to the “$RECYCLE” somehow throwing the script off?<\/p>\n<\/blockquote>\n<\/aside>\n
Ah, yeah, that would do it. You should enclose it in literal quotes (’ - single quotes mean literal)<\/p>\n
Get-ChildItem 'F:\\Home\\userabc\\My Documents\\$RECYCLE.BIN' | Remove-Item -recurse\n<\/code><\/pre>\nThe other option is to escape the $ with the ` grave key<\/p>\n
Get-ChildItem \"F:\\Home\\userabc\\My Documents\\`$RECYCLE.BIN\" | Remove-Item -recurse\n<\/code><\/pre>\nI think one of those may work.<\/p>\n<\/blockquote>\n<\/aside>\n
So the script no longer errors, but it’s not deleting the files within the $RECYCLE.BIN for the user. Tried with the -force switch too<\/p>\n<\/blockquote>\n<\/aside>\n
You must run it in the user’s context.<\/p>","upvoteCount":0,"datePublished":"2019-08-27T10:10:25.000Z","url":"https://community.spiceworks.com/t/emptying-recycle-bin-in-multiple-locations/727375/8","author":{"@type":"Person","name":"overdrive","url":"https://community.spiceworks.com/u/overdrive"}},{"@type":"Answer","text":"\n\n
<\/div>\n
BSOD'D:<\/div>\n
\nIf I want to go with small steps first, instead of whole hog, will the below work for one user? Taking into account, I only want to delete from the $RECYCLE.BIN and nothing else<\/p>\n<\/blockquote>\n<\/aside>\n
Yeah that should work fine - The first line is only looking for subfolders that literally have the name ‘$RECYCLE.BIN’, so unless your users have decided to create some subfolders with that name too it wont remove anything else. Just make sure to only use single quotes as Jrx said<\/p>","upvoteCount":0,"datePublished":"2019-08-27T10:22:21.000Z","url":"https://community.spiceworks.com/t/emptying-recycle-bin-in-multiple-locations/727375/9","author":{"@type":"Person","name":"francishagyard2","url":"https://community.spiceworks.com/u/francishagyard2"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Adam (AJ Tek):<\/div>\n
\n\n\n
<\/div>\n
BSOD'D:<\/div>\n
\n\n\n
<\/div>\n
Jrx1216:<\/div>\n
\n\n\n
<\/div>\n
BSOD'D:<\/div>\n
\n\n\n
<\/div>\n
Jrx1216:<\/div>\n
\n<\/blockquote>\nI would try<\/p>\n
Get-ChildItem \"F:\\Home\\userabc\\My Documents\\$RECYCLE.BIN\" | Remove-Item -recurse\n<\/code><\/pre>\nYou don’t need the “*”, you’re already getting the child items from that folder. I could be wrong, but I think that’s what’s preventing it from working just from a glance.<\/p>\n<\/blockquote>\n<\/aside>\n
Ah, I realize now that I had an extra “*”- “F:\\Home\\userabc\\My Documents$RECYCLE.BIN__*__”<\/p>\n
I ran it without it and still get the below<\/p>\n
Cannot find path 'F:\\Home\\userabc\\My Documents\\.BIN' because it does not exist\n<\/code><\/pre>\nYou’ll note it’s barking because the $RECYCLE, is this due to the “$RECYCLE” somehow throwing the script off?<\/p>\n<\/blockquote>\n<\/aside>\n
Ah, yeah, that would do it. You should enclose it in literal quotes (’ - single quotes mean literal)<\/p>\n
Get-ChildItem 'F:\\Home\\userabc\\My Documents\\$RECYCLE.BIN' | Remove-Item -recurse\n<\/code><\/pre>\nThe other option is to escape the $ with the ` grave key<\/p>\n
Get-ChildItem \"F:\\Home\\userabc\\My Documents\\`$RECYCLE.BIN\" | Remove-Item -recurse\n<\/code><\/pre>\nI think one of those may work.<\/p>\n<\/blockquote>\n<\/aside>\n
So the script no longer errors, but it’s not deleting the files within the $RECYCLE.BIN for the user. Tried with the -force switch too<\/p>\n<\/blockquote>\n<\/aside>\n
You must run it in the user’s context.<\/p>\n<\/blockquote>\n<\/aside>\n
I was running with -whatif to test<\/p>","upvoteCount":0,"datePublished":"2019-08-30T07:10:25.000Z","url":"https://community.spiceworks.com/t/emptying-recycle-bin-in-multiple-locations/727375/10","author":{"@type":"Person","name":"bsod","url":"https://community.spiceworks.com/u/bsod"}}]}}
bsod
(BSOD'D)
August 27, 2019, 9:04am
1
We have folder redirection setup for My Documents and I have noticed that there are $RECYCLE.BIN showing up in several different locations. I have seen several posts about issues with recycle bin and folder redirection. I have seen them located in My Documents and Favorites, although users won’t always have them in one or both, indeed some users don’t have it at all.
Is there a PowerShell script that can search out all $RECYCLE.BIN instances on a drive and empty them no matter where they are located
I know that the recycle bin can be turned off to delete files straight away, that’s not what I want do right now
I have a rudimentary script:
Get-ChildItem "F:\Home\userabc\My Documents\$RECYCLE.BIN\*" | Remove-Item -recurse
When I run it with or without the ", it fails to find the $RECYCLE.BIN in that location.
I am running PowerShell as system, as per this link too, to see if it’s a rights issue.
7 Spice ups
Jrx1216
(Jrx1216)
August 27, 2019, 9:28am
2
I would try
Get-ChildItem "F:\Home\userabc\My Documents\$RECYCLE.BIN" | Remove-Item -recurse
You don’t need the “*”, you’re already getting the child items from that folder. I could be wrong, but I think that’s what’s preventing it from working just from a glance.
2 Spice ups
bsod
(BSOD'D)
August 27, 2019, 9:33am
3
Jrx1216:
I would try
Get-ChildItem "F:\Home\userabc\My Documents\$RECYCLE.BIN" | Remove-Item -recurse
You don’t need the “*”, you’re already getting the child items from that folder. I could be wrong, but I think that’s what’s preventing it from working just from a glance.
Ah, I realize now that I had an extra “*”- “F:\Home\userabc\My Documents$RECYCLE.BIN__*__”
I ran it without it and still get the below
Cannot find path 'F:\Home\userabc\My Documents\.BIN' because it does not exist
You’ll note it’s barking because the $RECYCLE, is this due to the “$RECYCLE” somehow throwing the script off?
1 Spice up
Jrx1216
(Jrx1216)
August 27, 2019, 9:37am
4
BSOD'D:
Jrx1216:
I would try
Get-ChildItem "F:\Home\userabc\My Documents\$RECYCLE.BIN" | Remove-Item -recurse
You don’t need the “*”, you’re already getting the child items from that folder. I could be wrong, but I think that’s what’s preventing it from working just from a glance.
Ah, I realize now that I had an extra “*”- “F:\Home\userabc\My Documents$RECYCLE.BIN__*__”
I ran it without it and still get the below
Cannot find path 'F:\Home\userabc\My Documents\.BIN' because it does not exist
You’ll note it’s barking because the $RECYCLE, is this due to the “$RECYCLE” somehow throwing the script off?
Ah, yeah, that would do it. You should enclose it in literal quotes (’ - single quotes mean literal)
Get-ChildItem 'F:\Home\userabc\My Documents\$RECYCLE.BIN' | Remove-Item -recurse
The other option is to escape the $ with the ` grave key
Get-ChildItem "F:\Home\userabc\My Documents\`$RECYCLE.BIN" | Remove-Item -recurse
I think one of those may work.
2 Spice ups
bsod
(BSOD'D)
August 27, 2019, 9:43am
5
Jrx1216:
BSOD'D:
Jrx1216:
I would try
Get-ChildItem "F:\Home\userabc\My Documents\$RECYCLE.BIN" | Remove-Item -recurse
You don’t need the “*”, you’re already getting the child items from that folder. I could be wrong, but I think that’s what’s preventing it from working just from a glance.
Ah, I realize now that I had an extra “*”- “F:\Home\userabc\My Documents$RECYCLE.BIN__*__”
I ran it without it and still get the below
Cannot find path 'F:\Home\userabc\My Documents\.BIN' because it does not exist
You’ll note it’s barking because the $RECYCLE, is this due to the “$RECYCLE” somehow throwing the script off?
Ah, yeah, that would do it. You should enclose it in literal quotes (’ - single quotes mean literal)
Get-ChildItem 'F:\Home\userabc\My Documents\$RECYCLE.BIN' | Remove-Item -recurse
The other option is to escape the $ with the ` grave key
Get-ChildItem "F:\Home\userabc\My Documents\`$RECYCLE.BIN" | Remove-Item -recurse
I think one of those may work.
So the script no longer errors, but it’s not deleting the files within the $RECYCLE.BIN for the user. Tried with the -force switch too
1 Spice up
Unless you use the -Force parameter I don’t believe Get-ChildItem returns hidden items (which is both the bins and the items within the bins). If you want to empty all of them see if this works:
$RecycleBins = Get-ChildItem -Path 'D:' -Filter '$RECYCLE.BIN' -Recurse -Force | Where {$_.PSIsContainer}
ForEach ($Bin in $RecycleBins) {Get-ChildItem -Path $Bin.FullName -Force | Remove-Item -Force -Recurse}
2 Spice ups
bsod
(BSOD'D)
August 27, 2019, 10:09am
7
francishagyard2:
Unless you use the -Force parameter I don’t believe Get-ChildItem returns hidden items (which is both the bins and the items within the bins). If you want to empty all of them see if this works:
$RecycleBins = Get-ChildItem -Path 'D:' -Filter '$RECYCLE.BIN' -Recurse -Force | Where {$_.PSIsContainer}
ForEach ($Bin in $RecycleBins) {Get-ChildItem -Path $Bin.FullName -Force | Remove-Item -Force -Recurse}
If I want to go with small steps first, instead of whole hog, will the below work for one user? Taking into account, I only want to delete from the $RECYCLE.BIN and nothing else
$RecycleBins = Get-ChildItem -Path 'F:\Home\userabc\My Documents\' -Filter '$RECYCLE.BIN' -Recurse -Force | Where {$_.PSIsContainer}
ForEach ($Bin in $RecycleBins) {Get-ChildItem -Path $Bin.FullName -Force | Remove-Item -Force -Recurse}
overdrive
(OverDrive)
August 27, 2019, 10:10am
8
You must run it in the user’s context.
BSOD'D:
If I want to go with small steps first, instead of whole hog, will the below work for one user? Taking into account, I only want to delete from the $RECYCLE.BIN and nothing else
Yeah that should work fine - The first line is only looking for subfolders that literally have the name ‘$RECYCLE.BIN’, so unless your users have decided to create some subfolders with that name too it wont remove anything else. Just make sure to only use single quotes as Jrx said
bsod
(BSOD'D)
August 30, 2019, 7:10am
10
I was running with -whatif to test