Quickly Recreate Shares on Windows Servers

So you’re upgrading your server and you need to either recreate all you network shares or you’ve moved data to another drive and you want to reshare your data. With a few simple commands and a little bit of excel you can quickly make this happen.

Net Shares Command

The first thing you need to do is get a list of your current shares. So on your sever open up a command prompt and type the following: net share > c:\shares.txt

This will generate the a test file called shares.txt with all of your shares listed. The unfortunate thing is that Microsoft for some dumb reason will sometimes split the results for a single share over two lines, but that is still pretty easy to deal with.

Cleanup

Open the shares.txt file in Excel. You will need to do a little clean up to get everything the way you need it. In the end you need to just three three columns of information. The first is the share name, the second is the location of the directory to be shared and the third is the remarks and/or description field. You can also use this time to modify any of the drive locations, etc. Here is an example.

Example Excel Cleanup of Shares

Formula to Recreate Shares

So now that we have our information ready, we’re going to turn it into a DOS batch file that will create/modify our shares. The first step is use our shares information to create the necessary DOS commands. We’re going to use an Excel formula to do the heavy lifting. In this case we want to use the text in the first three columns to produce a single command that looks like this:
NET SHARE APPS=F:\Applications

The formula that you will need to place in Column D is as follows:
=IF(C2="","NET SHARE "&A2&"="&B2,"NET SHARE "&A2&"="&B2&" /REMARK:"""&C2&"""")

Now just copy and paste the formula into all of the necessary rows to complete your prep of the net shares commands.

Creating and Using the Batch File

Once you have verified all of your entries are correct. Copy the contents of your Net Shares column (Column D). Paste that into an empty text document, and change the extension to .bat. Now run your batch file while logged onto the console of the server and presto your shares have been recreated.

With a little work you can also use this script to delete and/or modify existing shares too.

Windows Server 2003 Gotchas

The way we have our network setup, we use NTFS permissions for controlling access to files, not the shares permissions. Microsoft Windows Server 2003 changed the default share behavior for the Everyone group. They removed the FULL access control on the share and changed it to READ, so in our case we just modify the formula to add the correct permission back. To do that we just tack the following to the end of the formula :&" /GRANT:Everyone,Full"

Advertisements
Leave a comment

3 Comments

  1. WRX99D

     /  September 6, 2007

    Great article mate

  2. WRX99D

     /  September 6, 2007

    Great article mate – used it loved it.

  3. Roy

     /  September 13, 2010

    Thanks lot. Worked great for me.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: