Skip to content

Instantly share code, notes, and snippets.

@JohnLBevan
Last active October 23, 2022 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JohnLBevan/518695b56d2dfd490ee68a53a9bad1a0 to your computer and use it in GitHub Desktop.
Save JohnLBevan/518695b56d2dfd490ee68a53a9bad1a0 to your computer and use it in GitHub Desktop.
Get Ownership of / Access To Files
:: Recursively take ownership of all files under a folder, and amend their access to grant full ownership to admins.
takeown /R /A /D Y /F c:\temp\path
:: /R = Recursive
:: /A = Ownership to Admins
:: /D Y = answer Yes to any questions (/D N would answer No)
:: /F c:\temp\path = which path to run the command against
icacls c:\temp\path /grant Administrators:F /T /C
:: c:\temp\path The path to run the command against
:: /grant Administrators:F = Grant Full permissions to Administrators group
:: /T = Recursive
:: /C = Continue on error
robocopy /MIR /Z /W:1 /R:1 c:\temp\path\source c:\temp\path\dest
:: for my scenario, I was copying contents from old HDDs to long term storage, so after getting access to
:: all files on the target drive, I used robocopy to sync the contents over
:: (here I used mirror, which would sync any future changes to the source too; redundant in my use case, but often a useful script)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment