How to delete hundreds of shared directories.

Sheldon Livingston
Sheldon Livingston used Ask the Experts™
on
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.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
JohnBusiness Consultant (Owner)
Most Valuable Expert 2012
Expert of the Year 2018

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 LivingstonConsultant

Author

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)
Most Valuable Expert 2012
Expert of the Year 2018

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.
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Sheldon LivingstonConsultant

Author

Commented:
???  Thanks John.

Anyone else?
kevinhsiehNetwork Engineer

Commented:
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 Engineer
Distinguished Expert 2017

Commented:
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 LivingstonConsultant

Author

Commented:
Thanks Tom... but the folders are all under one share and they are a subset of the folders within the share.
Tom CieslikIT Engineer
Distinguished Expert 2017

Commented:
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 CastroTop Rated Freelancer on MS Technologies
Awarded 2018
Distinguished Expert 2018

Commented:
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 Engineer

Commented:
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
Consultant
Commented:
I used

RD /S /Q "Path of folder"

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial