How to delete hundreds of shared directories.

I'd like to delete the contents for 4 directories in Server 2008 R2.

These directories and their sub-directories are shared.

Trying to delete gives a warning prompt that they are shared and users will not be able to access them any longer.

There are hundreds of directories to delete.

Is there a way to automate this?

del *.* /F /Q fails.
Sheldon LivingstonConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JohnBusiness Consultant (Owner)Commented:
One way (not at all long) is to open Explorer, highlight all the files, click on Delete and delete what you can.

You may want User to log off while you do this. This will help inform you on using your script
Sheldon LivingstonConsultantAuthor Commented:
John... I am trying to avoid having to confirm the deletion of shared folders hundreds of times.  Via Explorer you are prompted for every shared folder.
JohnBusiness Consultant (Owner)Commented:
Go into the folder and delete the files. That is really easy to do and may give you some insight into what cannot be deleted.

My suggestion is a learning exercise to help you with the deletion script.
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

Sheldon LivingstonConsultantAuthor Commented:
???  Thanks John.

Anyone else?
kevinhsiehCommented:
All of the shares are defined in the registry. You can export the registry key, modify it to delete all the shares you don't want anymore, and then restart the lanmanserver server to complete the deleting of the shares. Then you should have no issue deleting the directories.

https://www.itprotoday.com/windows-8/q-there-easy-way-back-and-restore-share-permissions-defined-windows-xp-or-windows-vista
Tom CieslikIT EngineerCommented:
Go to Computer management and delete all shares you want to clean
After that you will be able to delete all of them if you are computer / domain admin and you inherit all rights from root

Capture.JPG
Sheldon LivingstonConsultantAuthor Commented:
Thanks Tom... but the folders are all under one share and they are a subset of the folders within the share.
Tom CieslikIT EngineerCommented:
So if there is only one share folder, just go to properties and security, Advance, Owner,

Click Edit and Take ownership, select all subfolders
Click OK, and close all
Go back to same place, then in Permissions click Change Permissions assign all permissions to yourself, then select checkbox

Replace all child object permissions with inheritable permissions from this object
Click OK.
Now you should have ALL permissions to all subfolders and files.,

Now You can delete them all
Jose Gabriel Ortega CastroEE Solution Guide/Topic Advisor and CEO Faru Bonon ITCommented:
Find out the name and physical locations on the server of all the shares that you want to remove (just the Root)

on CMD :   "Net Share"
Get the physical URLs

Open in new window



Example of removal of the emails:

gci -Directory -Path F:/ -directory | where{ $_.Name -like "123"} | Remove-Item

Open in new window



"address1","address2","adddress3" |  gci -Directory -Path F:/ -directory | where{ $_.Name -like "123"} | Remove-Item

Open in new window

Where addressN is the physical paths that you got on the net share (just the root folders)
Mike TLeading EngineerCommented:
Hi,

It depends - do you know scripting in VBScript or PowerShell. I would recommend PowerShell but don't know off the top of my head a script.
I would definitely not use the GUI.

Mike
Sheldon LivingstonConsultantAuthor Commented:
I used

RD /S /Q "Path of folder"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows OS

From novice to tech pro — start learning today.