• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 274
  • Last Modified:

Windows File Server - Get Access to all Files on NTFS Share

I have a Windows 2012 Filecluster.  As I am during a fileserver migration, I need to delete all files and folders from the department share.  Although I am domain admin, I don't have access to all folders / files.

I can take ownership manually and grant myself access to the files.  As there is a large amount of files, I would like to run this automated e.g. using a batch or powershell.

How can I get access to all files on my fileshare?

Thanks!
0
whenz
Asked:
whenz
  • 2
2 Solutions
 
Tony GiangrecoCommented:
Here is the powershell command to delete all files in a folder

Remove-Item c:\folder_name\*
0
 
Santosh GuptaCommented:
Hi,

Try this to take ownership, you can change your path (currently d:\), run it as command and leave it.

forfiles /p d:\ /s /m *.* /c "cmd /c takeown /f @path"
0
 
jrhelgesonCommented:
I understand that you are taking control of the files in order to delete them.  This is what you need.  These commands will take ownership, then grant full permissions to Domain Admins - which you can then use to delete the files.

Two commands you need: "Takeown" and "icacls".
takeown.exe /F * /D /A /R
for /D %%I in (*) DO iCACLS.exe "%%I" /T /grant "%USERDNSDOMAIN%\Domain Admins":F /inheritance:e

Open in new window


Browse to the root of the directory that you want to take control over all the sub-folders and files.  Then run those two commands.

From the command prompt, type "Takeown" or "icacls" and you'll see all the command options.
For Takeown, the '/F' specifies the file or folder, which I put as * to specify all files/folders.  '/D' suppresses the confirm prompt, '/A' gives ownership to administrators group rather than current logged in user, and '/R' tells it to recurse the folders and touch all the subfolders.

On the icacls line, you can replace %USERDNSDOMAIN% with your existing DNS domain, i.e. "domain.local\Domain Admins"
0
 
jrhelgesonCommented:
Alternately, you can create an empty folder on a different drive, then use Robocopy with the "/B" (backup) mode, combined with /PURGE to delete files without having to take ownership of them.

1) Create directory C:\FOO
2) Files to be deleted: D:\OLDDATA\  (all files, folders & subfolders)

Robocopy command:
robocopy C:\FOO D:\OLDDATA /B /PURGE /NOCOPY

Open in new window

The /B runs the command in backup mode, which invokes it as a system process and bypasses file permissions, the /PURGE will delete any files not found in the source.  You may need to specify /E to recurse into sub-folders, but I don't think so.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now