Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create the same folder in everyone's home folder

Posted on 2013-11-11
6
Medium Priority
?
335 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 85

Accepted Solution

by:
oBdA earned 2000 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
Technology Partners: 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!

 
LVL 57

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

When it comes to writing scripts for a Client/Server computing environment it is essential to consider some way of enabling the authentication functionality within a script. This sort of consideration mainly comes into the picture when we are dealin…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

715 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