Create a folder on first login with Ownership rights (Not Home Directory)

Hi,
I need to create folders for almost 2000 users where they can archive their emails. Other users should not be able to see each other's folders(Just like user drive) Need to assign full rights on that folder. Task is to also map it on users' first login.

net use t: /delete
net use t: \\servername\sharedfolder\%Username%(With Full rights on the folder)

Note: I cannot use Home Directory/User drive. We are using Windows 2012 R2, client machines are all Windows 7.

Any suggestions or script will help....
maliks121Asked:
Who is Participating?
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.

Davis McCarnOwnerCommented:
MD T:\Mail-Archive after your net use and as part of a login script.
0
Lionel MMSmall Business IT ConsultantCommented:
this won't map a drive
net use t: \\servername\sharedfolder\%Username%
so I assume you mean
net use t: \\servername\%Username%
As such I also assume you want user, let's say Bob, to have a folder created on the server when the user Bob first signs on? If so then user cannot create a folder on a server, share it, and assign permissions to it--this user could do this to their local drive but not on the server itself. You could however use GPO to run a script "when user first logs on" to create a scheduled task on the server and then have that do the required work or we could create a small batch file that you can run each time you create a new user that would run this task for you automatically.
1
maliks121Author Commented:
So you are suggesting to map the drive with "net use", then create a GPO for "When User First Logs On"  and use script to assign permissions on the folder.
Sounds good to me!
Do you have any KB i can follow or script that I can use for scripting
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Davis McCarnOwnerCommented:
Create an MS-DOS bat file with the net use and MD (MakeDirectory) commands and the push it using GPO.  The creator will be the default owner.
1
Lionel MMSmall Business IT ConsultantCommented:
OK create a batch file (do you know how?) and give it a name like CreateNewUser.Bat and add these lines

@echo on
REM Change current directory to the [d]rive and [p]ath the batch file is in
pushd "%~dp0"
REM Prompt to Enter the User's Username
set /p param1=Enter Username:  
if "%param1%"=="" (
  echo You must enter the User's Username
  exit /b
)

Echo %param1%
pause
Rem      Add your servername (COMPUTERNAME) here
Set Server=YourServerName
Rem      Add your Domain here
Set Domain=YourDomain

Rem       Create the user's directory to store email archive
md d:\users\%param1%

Rem      Remove existing permissions and replace with new
icacls d:\users\%param1% /reset
icacls d:\users\%param1% /inheritance:r /grant:r %Domain%\%param1%:(OI)(CI)F /T

Rem      Take Owership of the Directory for the User (not required)
takeown /s %Server% /u %Domain%\%param1% /f d:\users\%param1% /r /d:n

Rem      Create the required share for the user
Net Share %param1%=D:\Data\%param1% /Grant:%param1%,Full /Remark:"D:\Data\%param1%"

:End
Exit

You can then create a shortcut to this file or run it from a command prompt. Only thing left to do now is to add the net use t: to your logon script (do you already use one?); add
net use t: /d
net use t: \\server-name\%username%
2

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
NVITCommented:
FYI: No points needed. Just helping...

Since you have around 2000 users....If all your users are on same domain, and with slight changes to Lionelmm's script, you could save some time and setup all user at one pass. Do this by...

- Changing Lionelmm's script, replacing the prompt section for param1, up to the PAUSE line, with:
set param1=%1

Open in new window


- Putting user names in a .txt file:
NET USERS /DOMAIN > users.txt

Open in new window


Note: you should start with a few names in users.txt to be sure it works. After you're satisfied, do the rest.

- Edit users.txt, putting each user name in one line

- Make the folders by passing user.txt file to the script:
for /f %a in (users.txt) do (call CreateNewUser.bat %a)

Open in new window

0
Lionel MMSmall Business IT ConsultantCommented:
NVIT -- I agree with you -- I TOTALLY FORGOT that he needed this for 2000 users -- I was going on the premise of needing to do this for NEW users. However if they want to do this for all users, existing users then you approach for getting that list of users is much better --thanks for catching that.
0
Lionel MMSmall Business IT ConsultantCommented:
have you tried, tested the suggested solution yet?
0
Lionel MMSmall Business IT ConsultantCommented:
This is what was asked for and this was an added help so both should get awarded points; so I suggest 300 and 200
0
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
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.