?
Solved

Need a script to create a folder with names in the file and permissions to the same username

Posted on 2007-07-31
16
Medium Priority
?
317 Views
Last Modified: 2010-03-05
Hi,

I have a file which has all the usernames.So need to create a folder in the same name and give permissions to the share and security to the same user automatically.

Regards
Sharath
0
Comment
Question by:bsharath
  • 6
  • 5
  • 5
16 Comments
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 19605907
Type the following sequence of commands (NOT in a batch file), pressing the keys specified in <>:

copy con y.txt
y<enter>
<CTRL+Z>

Then, create a batch file:

for /f "tokens=1" %%a in (usernames.txt) do (
   md %%a
   cacls %%a /t /c /g %%a:F "domain admins":f system:f<y.txt
)
0
 
LVL 11

Author Comment

by:bsharath
ID: 19606428
When i type copy con y.txt in the cmd prompt it goes on reading and nothing happens
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19606618
Are the names listed in the file login names for AD or Full names(first last / Last, First) from AD?

and do you want the shares hidden or visable? with admin rights as well as user? Owner to admin's or user?

zf
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 11

Author Comment

by:bsharath
ID: 19606627
I have the users Nt login names in the file
I want the folder to have his name in the security permissions and everyone in the Share permissions
I want the share to be visible.Owner has to be the user.The creator thats the machine in which i create has to have the access to read/write
0
 
LVL 11

Author Comment

by:bsharath
ID: 19609978
Any help...
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19610197
I have started a script for this, will not be a problem to complete.  Will not be able to finish until this evening, will post back when Im done.

zf
0
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 19614293
@zoofan,

how are you writing this?  vbscript?  no wonder it's taking so long.

@bshararth,

That's right, when you type
COPY CON Y.TXT
and press enter you get NOTHING but a flashing cursor.  That's why I said to type things in the sequence I specified.

At that first blank line, type the letter Y then press enter.  Then press CTRL+Z and then press enter to save the file (a "^Z" will appear) - this is an ancient (for computers) method of creating a text file - the reason I said to do it this way is that it's important that you get the enter key in their.

If you need to actually "see" what I'm talking about, see:
http://www.lwcomputing.com/extrahelp/createytxt.wmv
0
 
LVL 11

Author Comment

by:bsharath
ID: 19614342
leew
Thanks your way is creating the folder but its not sharing the folder and giving the permissions to the share as everyone and security permissions to the creator and the username as full access.
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19614355
My appologize, am still at work.  Will get right on it when I get home.  And yes sadly your right I am extremely slow,  the eval on my typing tutor ran out and I never purchased it.  And  if you  think Im slow with vbs you should see me with assembly, dear god the cows came home with grand kids last time.

cheers


zf
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19614383
Bsharath,do you need to do just share permissions or NTFS file permissions as well?  And if NTFS file permissions as well do you have any obejections to using xcacls.exe from the MS rk?


zf
0
 
LVL 11

Author Comment

by:bsharath
ID: 19614391
No problem Zoofan
I know xcalcs can only do this.

I need the share permissions to be for evertone full access
and NTFS permissions for the user whose folder is created and the creator
0
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 19614393
for /f "tokens=1" %%a in (usernames.txt) do (
   md %%a
   cacls %%a /t /c /g %%a:F "domain admins":f system:f<y.txt
   net share %%a=x:\path\to\folder\%%a /grant:everyone,full
)

The above will create a folder based on the username in the text file, assign the SYSTEM account, the user account, and the Domain Administrators FULL CONTROL on NTFS permissions, and grant EVERYONE FULL CONTROL over the SHARE - which shouldn't matter much given that NTFS permissions secure everything.

I would strongly encourage you to start reading up on these commands, especially if you need things to be a little different.  I know it's easy to keep having us do this for you, but you will learn better and be a better administrator if you learn how to do this stuff yourself.  Any command you are not familiar with, you can try typing the command name /? and a help menu will normally be displayed.  In addition, you can reference www.ss64.com - they have a list of almost all command line tools ever shipped with Windows or a Windows resource kit type package as well as instructions and examples of how to use them.
0
 
LVL 97

Expert Comment

by:Lee W, MVP
ID: 19614396
I caution you - you should be making the folders accessible to the system account to help ensure antivirus software and other products on your server work appropriately.  In addition, domain admins should have access for administrative purposes - simply using creator owner will NOT grant access to all admins and could create problems.
0
 
LVL 12

Expert Comment

by:zoofan
ID: 19614439
Excellent point, and nice resource leew.

zf
0
 
LVL 11

Author Comment

by:bsharath
ID: 19614463
leew

for /f "tokens=1" %%a in (usernames.txt) do (
   md %%a
   cacls %%a /t /c /g %%a:F "domain admins":f system:f<y.txt
   net share %%a=x:\path\to\folder\%%a /grant:everyone,full
)

I have the calcs,Username.txt in C:\
Can you please tell me what i need to change in your batch file.
I will take you point and try to do.....
0
 
LVL 97

Accepted Solution

by:
Lee W, MVP earned 2000 total points
ID: 19614499
Not without knowing what you need specifically.

First off, I expect usernames.txt is the format of:

username1
username2
username3
etc

I'll break it down line by line:

The line below takes the username from the usernames.txt file as a "token" and assigns it to the variable %%a
for /f "tokens=1" %%a in (usernames.txt) do (

This creates the folder CURRENTFOLDER\%%a - again %%a is a variable, so you'll have CURRENTFOLDER\username1, CURRENTFOLDER\username2, etc.
   md %%a

This changes permissions on the folder %%a, /t tells it to change the access control lists (ACLS/permissions), the /C is to continue on errors, and the /g means to GRANT the user %%a:F(ull Control).  Then grant Domain Admins Full Control, then grant SYSTEM full control.  Finally, use the contents of the file y.txt to answer the prompt "are you sure" that cacls will generate.
   cacls %%a /t /c /g %%a:F "domain admins":f system:f<y.txt

This command creates a shared folder with the share name %%a - the path to that shared folder on the server is specified as x:\path\to\folder\%%a.  So for example, if you are running this command from the D:\USERS folder, then the path following the = sign would be D:\USERS\%%a.  Then the /grant:everyone,full does what it implies - it says to set the share permissions so that the everyone group has FULL CONTROL.
   net share %%a=x:\path\to\folder\%%a /grant:everyone,full
)


I'll expand the script a little:


@echo off
Rem Change the next line following the = to be the path to your users folder.
set UserFolderPath=X:\Path\To\Put\User\Folders
for /f "tokens=1" %%a in (c:\usernames.txt) do (
   md "%UserFolderPath%\%%a"
   cacls "%UserFolderPath%\%%a" /t /c /g %%a:F "domain admins":f system:f<y.txt
   net share %%a="%UserfolderPath%\%%a" /grant:everyone,full
)
0

Featured Post

Industry Leaders: 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

Issue: One Windows 2008 R2 64bit server on the network unable to connect to a buffalo Device (Linkstation) with firmware version 1.56. There are a total of four servers on the network this being one of them. Troubleshooting Steps: Connect via h…
Understanding the various editions available is vital when you decide to purchase Windows Server 2012. You need to have a basic understanding of the features and limitations in each edition in order to make a well-informed decision that best suits …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Suggested Courses

621 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