Solved

Create the same folder in everyone's home folder

Posted on 2013-11-11
6
327 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 83

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 52

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
A short film showing how OnPage and Connectwise integration works.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now