?
Solved

Script to create multpile folders with sharenames

Posted on 2006-05-10
9
Medium Priority
?
970 Views
Last Modified: 2008-01-09
Hi I need to create a home folder for 50 users. Does anyone know a vb script that can autogenerate x-number of folders with  foldernames & sharenames. It can extract the names from a .csv file eg: names.csv - where the fields are foldernames, sharenames. So the 1st folder can be "Sales_Tom" & the sharename "btom$"

I know nutz about scripting...any help would be great!! Please advise.

0
Comment
Question by:titanax
  • 5
  • 4
9 Comments
 
LVL 14

Expert Comment

by:canali
ID: 16647339

Assuming your  file is : sss.cvs
and
all fields to be "foldernames","sharenames":
"Sales_Tom","btom$"


this is the script (all shares created  by the script are everyone full control !!!!)

bye _GAS_

@echo off
set folderN=
set shareN=
set tmp=
:: where folder
set p2s=c:\sharedHome
:: make folder
mkdir %p2s% 1> NUL 2> nul
:: if folder dose not exist:
if not exist %p2s%\nul goto :_ERR
:: assuming , as filelds separetor
for /f "tokens=1,2 delims=," %%a in (sss.cvs)  do (
  rem --- strip "pluto" become pluto  
  set tmp=%%a
  set folderN==%tmp:~1,-1%
  set tmp=%%b
  set shareN=%tmp:~1,-1%
  set tmp=
  rem --- make folder
  mkdir %p2s%\%folderN%
  if not exist %p2s%\%folderN%\nul goto :_ERR
  rem ---------------------------------------------------------------
  rem should be better have in the cvs file the username too
  rem and grant privilege only to respective user
  rem echo net share %shareN%=%p2s%\%folderN% /grant:%username%,full
  rem ---------------------------------------------------------------
  rem all shared dirs are full control for everyone !!!!!
  net share %shareN%=%p2s%\%folderN%  /grant:everyone,full

)
goto :_FINE

:_ERR
echo ERROR:Path not found...something go Wrong
goto :_FINE

:_FINE
0
 

Author Comment

by:titanax
ID: 16649367
Hi canali,

Thank you so much. Is this a batch file? I tried to put it as a .vbs & it didn't work. Even as a batch file there are some errors:

My supervisor now wants the script as a .vbs & the file in EXCEL format, just 2 rows as fields without the " " ie. Sales_Tom, btom$

Please advise...

Error:
------
D:\>create
A subdirectory or file d:\Home\ already exists.
The option /GRANT:everyone,full is unknown.

The syntax of this command is:

NET SHARE
sharename
          sharename=drive:path [/USERS:number | /UNLIMITED]
                               [/REMARK:"text"]
                               [/CACHE:Manual | Documents| Programs | None ]
          sharename [/USERS:number | /UNLIMITED]
                    [/REMARK:"text"]
                    [/CACHE:Manual | Documents | Programs | None]
          {sharename | devicename | drive:path} /DELETE

More help is available by typing NET HELPMSG 3506.

A subdirectory or file d:\Home\ already exists.
The option /GRANT:everyone,full is unknown.

The syntax of this command is:

NET SHARE
sharename
          sharename=drive:path [/USERS:number | /UNLIMITED]
                               [/REMARK:"text"]
                               [/CACHE:Manual | Documents| Programs | None ]
          sharename [/USERS:number | /UNLIMITED]
                    [/REMARK:"text"]
                    [/CACHE:Manual | Documents | Programs | None]
          {sharename | devicename | drive:path} /DELETE

More help is available by typing NET HELPMSG 3506.

A subdirectory or file d:\Home\ already exists.
The option /GRANT:everyone,full is unknown.

The syntax of this command is:

NET SHARE
sharename
          sharename=drive:path [/USERS:number | /UNLIMITED]
                               [/REMARK:"text"]
                               [/CACHE:Manual | Documents| Programs | None ]
          sharename [/USERS:number | /UNLIMITED]
                    [/REMARK:"text"]
                    [/CACHE:Manual | Documents | Programs | None]
          {sharename | devicename | drive:path} /DELETE

More help is available by typing NET HELPMSG 3506.

The system cannot find the batch label specified - _FINE

D:\>
0
 
LVL 14

Accepted Solution

by:
canali earned 2000 total points
ID: 16650350
the option GRANT is  implemented in windows 2003, not in windows 2000...

the batch script now is ok  tested (sorry for the fist one )
createshare.cmd
@echo off
:: where folder
set p2s=c:\sharedHome
:: make folder
mkdir %p2s% 1> NUL 2> nul
:: if folder dose not exist:
if not exist %p2s%\nul goto :_ERR
:: assuming , as filelds separetor
for /f "tokens=1,2 delims=, " %%a in (sss.cvs)  do (
  rem folderName %%a ---   shareName %%b
   rem --- make folder
  mkdir %p2s%\%%a    1> NUL 2> nul
  if not exist %p2s%\%%a\nul goto :_ERR
  rem ---------------------------------------------------------------
  rem should be better have in the cvs file the username too
  rem and grant privilege only to respective user
  rem echo net share net share %%a=%p2s%\%%b  /grant:%username%,full
  rem ---------------------------------------------------------------
  rem all shared dirs are full control for everyone !!!!!
  echo net share %%a=%p2s%\%%b
  net share %%b=%p2s%\%%a
  rem windows2003   net share %%a=%p2s%\%%b  /grant:everyone,full

)
goto :_FINE

:_ERR
echo ERROR:Path not found...something go Wrong
goto :_FINE

:_FINE
REM BYE _GAS_
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:titanax
ID: 16654908
"%%a in (sss.cvs)..." <------- here u mean sss.CSV right?

" rem should be better have in the cvs file the username too
  rem and grant privilege only to respective user
  rem echo net share net share %%a=%p2s%\%%b  /grant:%username%,full"

So you suggest I add the username in my csv? How can the script be modifed so that i don't have to add put " " in the entries of my sss.csv
eg:
foldername, sharename, username
tom, tom$, tom.jones
0
 

Author Comment

by:titanax
ID: 16654963
I'm getting this error:
"echo ERROR:Path not found...something go Wrong" after the 1st user is created.

I made 2 ammendments to your code:
set p2s=E:\HOME
for /f "tokens=1,2 delims=, " %%a in (sss.csv)  do (

The createshare.cmd & the sss.csv files are in E:\

This is my sss.csv
"tom", "tom$"
"sam", "sam$"
"cindy", "cindy$"

Only 1 folder is created Tom but there is no sharename.

Am  I doing something wrong?
0
 
LVL 14

Expert Comment

by:canali
ID: 16656687
The second script work fine with a sss.cvs without " was already modified...
sss.cvs
tom,tom$
sam,sam$
cindy,cindy$


I hope everythin is clear
Gas
0
 

Author Comment

by:titanax
ID: 16665033
yes it is clear...the folders are created fine :) but the shares don't always appear :(
0
 
LVL 14

Assisted Solution

by:canali
canali earned 2000 total points
ID: 16671581
Strange, I tryed it with XP pro and 2003serverR2 and worked fine:
the batch echoes the command executed copy & paste it in the command line and show the result:
some error, no permission to create hidden shares...
another chance is write down manually the file (with 2 or 3 line) and run the batch (avoid strange things at the end of the line generated by excel during exporting)
After the batch runned try F5 to refresh !!!
Gas
0
 

Author Comment

by:titanax
ID: 16719307
yup !! its working fine !
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

So you have two Windows Servers and you have a directory/folder/files on one that you'd like to mirror to the other?  You don't really want to deal with DFS or a 3rd party solution like Doubletake. You can use Robocopy from the Windows Server 200…
by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question