Solved

Is there a VB script to locate one or more home directories for a user?

Posted on 2011-03-25
8
248 Views
Last Modified: 2012-05-11
Is there a way, either VB script or batch file, to locate one or more home directories for a user?  

For example, my LAN ID, qnguye01, is found on two Windows file cluster nodes.  I want to be able to run a VB script or batch file to locate other end users' home directories, if they have one or more floating around somewhere.

TY,
Quan
0
Comment
Question by:qvn7
  • 3
  • 2
  • 2
  • +1
8 Comments
 
LVL 5

Expert Comment

by:xylog
ID: 35221914
This will return the home directory that is set in active directory:

dsquery user -samid usernam|dsget user -hmdir

0
 
LVL 45

Expert Comment

by:aikimark
ID: 35222074
where will this script run?
0
 

Author Comment

by:qvn7
ID: 35222598
@ xylog:

Thanks, but what I need is to locate other home directories that isn't the main one under the "Profile" tab in Active Directory.  

My main home directory folder is located here:

\\HomeServer1\SharedDrive1\SharedVol1\qnguye01

I recently found out that I had another one located somewhere else, like:

\\HomeServer3\SharedDrive4\SharedVol3\qnguye01

Is there a way to locate multiple home directories either using VB script, batch file or dsquery commands?

Thanks!!!
0
 

Author Comment

by:qvn7
ID: 35222599
@ aikimark

Where will this script run?  Either my primary workstation or one of the file servers hosting the home directories data.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 5

Expert Comment

by:xylog
ID: 35222798
If you want to locate a directory with a specific name in a specified location you can use a series of "if exist" statements in a batch file:

findhomes.bat
==========
@echo off
if exist \\HomeServer1\SharedDrive1\SharedVol1\%1 echo \\HomeServer1\SharedDrive1\SharedVol1\%1

if exist \\HomeServer3\SharedDrive4\SharedVol3\%1 echo \\HomeServer3\SharedDrive4\SharedVol3\%1

===========

to run:

findhomes qnguye01

Alternatively if you want to search the entire hard drive you can enumerate all the directories with a dir statement:

dir /ad /s |findstr qnguye01

This is a bit slow if you have many directories (say, more than several hundred)

There is a middle ground if you have many volumes you can loop thru them like so:

for /d %%i in (\\HomeServer1\SharedDrive1\*) do if exist  %%i\%1 echo %%i\%1

If you have multiple shares we can loop thru them with the net view command. For multiple servers best bet is to loop thru a list in a text file.
0
 
LVL 14

Accepted Solution

by:
yehudaha earned 500 total points
ID: 35226366
hello

edit line 1 to add your home folder server names

when it's ask for folder name you can input "like" name input, what do i mean:

if you look for " jack" folder but you not sure if there addition to the name like: "jackfolder".
you can put just jack and the script will search for any folder have jack in the name.
ArrComputers = Array("homeserver1,homeserver2")

dir = InputBox("Enter Directory Name")

For Each strComputer In ArrComputers
Set objWMIService = GetObject _
    ("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
   ("Select * From Win32_Directory Where name Like '%\\" & Dir & "%'")
   
For Each objFolder in colFolders
    Wscript.Echo "Found: " & objFolder.Name & " ON " & strComputer
Next
Next

MsgBox "done"

Open in new window

0
 

Author Comment

by:qvn7
ID: 35233004
Thanks for ALL of your help!!!  Have a good day!!!
0
 
LVL 14

Expert Comment

by:yehudaha
ID: 35234373
great, please close the question and choose the answer/s you like
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Welcome to part one of a multi-part tutorial series, VBScript for Windows System Administrators.  The goal of this series is to teach non-programmers how to write useful VBS code to automate their environment, and perform tasks faster, and in a more…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

12 Experts available now in Live!

Get 1:1 Help Now