Problem:
How do I get Ownership of a Directory back in Windows in NTFS?
Solution:
Check existing permissions:
Get-Acl -Path "E:\Client_Reports" | Format-Table -Wrap
Use set-acl:
$ACL = Get-Acl -Path "E:\ProblemFolder" $Account = New-Object System.Security.Principal.NTAccount("Builtin\Administrators") $ACL.SetOwner($Account) Set-Acl -Path "E:\ProblemFolder" -AclObject $ACL
Use takeown to take ownership:
takeown /a /r /d Y /f E:\ProblemFolder
Use icacls:
C:\>icacls "ProblemFolder" /grant Administrators:(OI)(CI)F /T
F = Full Control
CI = Container Inherit – This flag indicates that subordinate containers will inherit this ACE.
OI = Object Inherit – This flag indicates that subordinate files will inherit the ACE.
/T = Apply recursively to existing files and sub-folders. (OI and CI only apply to new files and sub-folders).
Finally you can try PSEXEC:
Open a command prompt with Administrator Privileges
CD into C:\temp\PSTools
Run:
psexec -s -i cmd.exe
This installs a temporary service which will open a command prompt under LOCAL SYSTEM account. The service will be automatically deleted after you close the screen (i.e. after EXIT)
Run:
TAKEOWN /F <folder> /R /D Y
this will set the Administrators group as owner, it also recurses into the folder
To give the Administrators group full control rights, run ICACLS <folder> /grant administrators:F /T; the /T indicates that this operation is performed on all matching files and directories below the directories specified