none
Include All Hidden Folders, Exclude $Recycle.Bin folder RRS feed

  • Question

  • Company is "emptying" everyone's personal network drive.  What we are actually doing is hiding all the files and folders.  I have a script that is mostly working, where I first take ownership of the files and folders, disable inheritance, remove all permissions, push new permissions down.  It works except when the user has several levels of subfolders.  The ownership portion of the script, is working through the array of Get-ChildItems in reverse order.  I then reverse the order again, and remove inheritance and begin working my way down through the folders.  The problem comes that at the lower folders (folders 3 or more deep), the script beings to not being able to "see" the files.  I'm seeing an improvement when I grab child items with the -Force at the very start.  The problem comes that I'm getting undesired folders, which I'm able to create an array that lists all the folders.  The only hidden folder I can't find a way to exclude is $Recycle.Bin.  With the $ symbol, it is treating it like a variable.  I'm not wanting to take ownership, or adjust the permissions on that folder.

    How do I use -Force, but exclude that folder?

    Sunday, November 1, 2020 10:09 PM

All replies

  • you could try this 2 quotes types: '$Recycle.Bin' and "$Recycle.Bin"

    you will see that 1st type (single quotes) will not interpret $Recycle as a variable 


    The opinion expressed by me is not an official position of Microsoft

    Sunday, November 1, 2020 11:35 PM