Link to home
Start Free TrialLog in
Avatar of Mick Finley
Mick FinleyFlag for United States of America

asked on

Folder Permissions and Powershell

I have roaming profiles which I need to delete.  By default these are created automatically when a user logs in and the user is the only one who can access them without manually taking ownership.  I have lots of these, regularly.  The below code is what I'm using, but it does not propagate to all folders under the root on one pass.  It will make me owner of the root folder on the first run, then individual folders on the second run and so on until I am finally owner of everything, might take 8-10 runs before I can actually delete the root user folder.

When manually taking ownership, there is a check box "Replace owner on subcontainers and objects", how do I do this with powershell.
Here is the code I've been using:

takeown /f $folder /R /D y
ICACLS $Folder /grant "$user:(CI)F" /T
Remove-Item $folder -Recurse -Force
SOLUTION
Avatar of Ganesh Anand
Ganesh Anand
Flag of Bahrain image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mick Finley

ASKER

My solution was a combination of the link Kumar posted and my modification of the code contained in the link.