Solved

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

Posted on 2014-03-28
4
262 Views
Last Modified: 2014-03-28
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
Comment
Question by:whenz
  • 2
4 Comments
 
LVL 25

Expert Comment

by:Tony Giangreco
Comment Utility
Here is the powershell command to delete all files in a folder

Remove-Item c:\folder_name\*
0
 
LVL 13

Assisted Solution

by:Santosh Gupta
Santosh Gupta earned 250 total points
Comment Utility
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
 
LVL 15

Accepted Solution

by:
jrhelgeson earned 250 total points
Comment Utility
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
 
LVL 15

Expert Comment

by:jrhelgeson
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction: I have always been a big fan of Windows but my liking towards it is slowly being eroded by the variety of other Applications that I encounter, when I browse the Web. Most of the software available is free and maybe Open Source too. …
Log files are useful in diagnosing and repairing problems.  This is a list of common log files and their standard locations that I've compiled.   While this is not exhaustive, it is a pretty good list that I've found to be useful.  I may update it f…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now