Solved

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

Posted on 2011-03-25
8
252 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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
 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Messed up my code 6 44
Recursive folder search vbscript 7 51
How can I save all open docs into a given folder 12 117
VBSScript Error IP Array 6 23
Unlike scripting languages such as C# where a semi-colon is used to indicate the end of a command, Microsoft's VBScript language relies on line breaks to determine when a command begins and ends. As you can imagine, this quickly results in messy cod…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 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