Restoring Administrative Access to Redirected Folders

Adam Jones - Systems Engineer

When you apply folder redirection to the My Documents folder, you can specify exclusive rights to the user’s folder. As an administrator, you might want to restore access to these folders. In order for folder redirection to work, the user must retain ownership of the redirected folder. This can make manually restoring administrative permissions a lengthy task. Fortunately, there is a handy script that you can use to update these permissions thanks to the My PKB blog found here: http://mypkb.wordpress.com/2008/12/29/how-to-restore-administrators-access-to-redirected-my-documents-folder/

You will need PsExec in order to complete this project as well as the powershell (PS1) script template below. Just follow the link above to the My PKB blog for instructions.

#ChangePermissions.ps1

# CACLS rights are usually

# F = FullControl

# C = Change

# R = Readonly

# W = Write

 

$StartingDir= "E:\Users\shares"

 

$Principal="INSERT_DOMAIN_NAME\INSERT_ADMIN_SBS"

 

$Permission="F"

 

$Verify=Read-Host `n "You are about to change permissions on all" `

"files starting at"$StartingDir.ToUpper() `n "for security"`

"principal"$Principal.ToUpper() `

"with new right of"$Permission.ToUpper()"."`n `

"Do you want to continue? [Y,N]"

 

if ($Verify -eq "Y") {

 

foreach ($file in $(Get-ChildItem $StartingDir -recurse)) {

#display filename and old permissions

write-Host -foregroundcolor Yellow $file.FullName

#uncomment if you want to see old permissions

#CACLS $file.FullName

 

#ADD new permission with CACLS

CACLS $file.FullName /E /P "${Principal}:${Permission}" >$NULL

 

#display new permissions

Write-Host -foregroundcolor Green "New Permissions"

CACLS $file.FullName

}

}