Solved

Create the same folder in everyone's home folder

Posted on 2013-11-11
6
325 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 51

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

760 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

18 Experts available now in Live!

Get 1:1 Help Now