Solved

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

Posted on 2011-03-25
8
251 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
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.

 
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

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

Suggested Solutions

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…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

863 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

19 Experts available now in Live!

Get 1:1 Help Now