Script to match share name to name of directory

Hey Experts.  I have 200+ directories on my file server that are used as the network share for each user.  We are migrating the file shares from a 2003 file server to a 2012 server and I've copied over the 200+ directories but I need to recreate the shares.  I would rather not do it manually, thus the request for a script to do it.  

The script would need to share the folder out so that the share name matches the name of the folder.  Anyone know a batch script that will work for this?

Thanks Experts!
LVL 9
samiam41Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

NVITEnd-user supportCommented:
This does it per server. See section "Backup and Restore of Share Permissions" http://social.technet.microsoft.com/wiki/contents/articles/408.how-to-back-up-and-restore-ntfs-and-share-permissions.aspx

If you use NTFS permissions on the share, you also have to Backup and Restore of NTFS Permissions.
Lee W, MVPTechnology and Business Process AdvisorCommented:
Test first:

Wouldn't a single command be better?

For /f "tokens=*" %a in ('dir /ad /b x:\users') do @net share %a=x:\users\%a /grant:%a:full

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
Steve KnightIT ConsultancyCommented:
We can soon do that ... but can you not also either use grou policy to map the drives and/or use a drive mapping through one share now, most people would now use something like a share called users$ connecting to the root of the area then the users map drives to:

\\server\users$\username

How are they mapping it at the moment, on their pc, through login script, home drive settings, group policy preferences etc?

If you do want to share, try this on the server.  If it looks right then remove the capital ECHO to make it do the sharing, assuming no spaces in the directories / usernames at the mo.

The For loop runs down all directories under what you set in BaseDir variable and sets %%a to each in turn

@echo off
Set BaseDir=D:\users
cd /d %BaseDir%
for /f %%a in ('dir /b /ad') do (
  ECHO NET SHARE %%a = %BaseDir%\%%~a /GRANT:%userdomain%\%%a,change
)

Open in new window


That will make a share called UserName and grant Change access to domain user.

Steve
samiam41Author Commented:
Hey Experts!

Thanks for your time and help with this.  I had to run to another set of fires and am just now getting a breather.  

I'm closing this out and awarding points and grade as I know you all need to focus on other questions and I need to work on another project which is now "critical".

You guys are the best!
samiam41Author Commented:
If any of you experts have a second, I'd greatly appreciate any help with this one!

http://www.experts-exchange.com/questions/28693485/Copy-file-permissions-in-batch-script-with-robocopy.html
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 Batch

From novice to tech pro — start learning today.