Solved

Create the same folder in everyone's home folder

Posted on 2013-11-11
6
329 Views
Last Modified: 2013-11-11
Hi,

I would like a script that will create the same folder in every user's home area. So I would like to create "Folder1" in \\server1\user1\Documents\   \\server1\user2\Documents   \\server1\user9999\Documents ...

But only create this folder if it doesn't already exist.

Is this possible?

Regrads
0
Comment
Question by:Net-Eng99
6 Comments
 
LVL 84

Accepted Solution

by:
oBdA earned 500 total points
ID: 39638516
Try this; just set the variables "UserShare" to the root of the user folders, and "CreateFolder" to whatever path and folder you want to create under the actual UserXXX folder.
The script is currently in test mode and will only display the "md" commands it would normally run. Remove the uppercase ECHO before "md" in line 9 to run it for real:
@echo off
setlocal
REM UNC to the root of the User folder:
set UserShare=\\server1\UserShare
REM Folder to create under each user's home folder:
set CreateFolder=Documents\Folder 1
for /d %%a in ("%UserShare%\*.*") do (
	echo Processing %%a ...
	if not exist "%%a\%CreateFolder%" ECHO md "%%a\%CreateFolder%"
)

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39638543
Assuming you can get to the server console, this should do it...remove the 'echo' on the last line to make it happen.
If you can't get to the console, map a network drive to the c$ of the remote server:
net use L: \\server1\c$
then adjust the 2nd line of the code to read
cd /d L:\users


@echo off
cd /d c:\users

for /f "delims=" %%a in ('dir /ad /b') do call :process "%%~fa"
goto :eof

:process
set fld=%1

if /i "%fld:~10,-1%" == "All Users" goto :eof
if /i "%fld:~10,-1%" == "Default User" goto :eof
if /i "%fld:~10,-1%" == "Public" goto :eof

echo Creating folder for %fld%
if not exist %fld:~0,-1%\Documents\Folder1" echo md %fld:~0,-1%\Documents\Folder1"

Open in new window

0
 
LVL 67

Expert Comment

by:sirbounty
ID: 39638544
Bah - didn't know oBdA was awake...forgot to refresh, sorry. :^)
0
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
LVL 53

Expert Comment

by:Bill Prew
ID: 39638565
Could be done right at a command line with a simple command like:

for /D %F in ("\\servername\basedir\*.*") do (md "%~F\Documents\Folder1" >NUL 2>NUL)

Open in new window

or in a BAT file as:

for /D %%F in ("\\servername\basedir\*.*") do (md "%%~F\Documents\Folder1" >NUL 2>NUL)

Open in new window

~bp
0
 

Author Comment

by:Net-Eng99
ID: 39638803
@oBdA thanks for your solution, I tried that one and it worked perfectly!

Regards
0
 

Author Closing Comment

by:Net-Eng99
ID: 39638805
Spot on solution - excellent!
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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