Avatar of Sheldon Livingston
Sheldon Livingston
Flag for United States of America asked on

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.
Windows OSWindows Server 2008

Avatar of undefined
Last Comment
Sheldon Livingston

8/22/2022 - Mon
John

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 Livingston

ASKER
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.
John

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.
Your help has saved me hundreds of hours of internet surfing.
fblack61
Sheldon Livingston

ASKER
???  Thanks John.

Anyone else?
kevinhsieh

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 Cieslik

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
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Sheldon Livingston

ASKER
Thanks Tom... but the folders are all under one share and they are a subset of the folders within the share.
Tom Cieslik

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 Castro

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)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Mike T

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
ASKER CERTIFIED SOLUTION
Sheldon Livingston

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.