Sheldon Livingston
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.
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.
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.
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.
My suggestion is a learning exercise to help you with the deletion script.
ASKER
??? Thanks John.
Anyone else?
Anyone else?
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
https://www.itprotoday.com/windows-8/q-there-easy-way-back-and-restore-share-permissions-defined-windows-xp-or-windows-vista
ASKER
Thanks Tom... but the folders are all under one share and they are a subset of the folders within the share.
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
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
Find out the name and physical locations on the server of all the shares that you want to remove (just the Root)
Example of removal of the emails:
on CMD : "Net Share"
Get the physical URLs
Example of removal of the emails:
gci -Directory -Path F:/ -directory | where{ $_.Name -like "123"} | Remove-Item
"address1","address2","adddress3" | gci -Directory -Path F:/ -directory | where{ $_.Name -like "123"} | Remove-Item
Where addressN is the physical paths that you got on the net share (just the root folders)
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
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You may want User to log off while you do this. This will help inform you on using your script