Page 1 of 2 12>
Topic Options
#144339 - 2005-07-27 01:44 AM Finding full path to homedirectory
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
Can anyone help me with a 'simple' scripting issue I have with locating the full path to a user's homedirectory please?

$user = GetObject("LDAP://cn=sillykid,ou=Test users,DC=greyhigh,DC=school,DC=nz")
? $user.homedirectory

returns

\\legolas\sillykid$

What I'd like is to be able to determine the full path to the homedirectory which in this case happens to be: D:\Homedirs\Students\sillykid where D: is on the server \\legolas.

Any thread would be appreciated.

Thank you

Top
#144340 - 2005-07-27 02:34 AM Re: Finding full path to homedirectory
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
Well what are the client types?

You can use ADSI/WMI to gather the locations of the shares I'm sure.

Let me look and see if I can find a snipet of code to do it

What OS is the Sever running NT4/2000/AD is it NT4 or AD Domain?

 

Top
#144341 - 2005-07-27 02:41 AM Re: Finding full path to homedirectory
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
This will list ALL shares. Using this you could do an InStr check for a specific user name if your user folders are named using the users logonID

Code:

Break On
Dim $SO
$SO=SetOption('Explicit','On')
$SO=SetOption('NoVarsInStrings','On')
$SO=SetOption('WrapAtEOL','On')
 

Dim $sComputer,$Servers,$objWMIService,$colShares,$objShare,$File,$Report
$sComputer='msef002'
$objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + $sComputer + "\root\cimv2")
$colShares = $objWMIService.ExecQuery("Select * from Win32_Share")
For Each $objShare In $colShares
$sComputer + " " + $objShare.Name + ' Path: ' + $objShare.Path ?
Next


 

Top
#144342 - 2005-07-27 02:48 AM Re: Finding full path to homedirectory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
that share thing is same you get with @homeshr

now... you can do it with adsi winnt provider or wmi.
here is the wmi way:
Code:

$server = "someServer"
$share = "someShare"

$objWMIService = GetObject("winmgmts:\\" + $server + "\root\cimv2")
For each $objItem in $objWMIService.ExecQuery("Select * from Win32_Share",,48)
if $share = $objItem.name
"there shared folder is: " $objItem.path ?
endif
next



I admit, I didn't write ready code but hope that gives you a pointer to the right direction...
_________________________
!

download KiXnet

Top
#144343 - 2005-07-27 02:49 AM Re: Finding full path to homedirectory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
wow! I was slow typing that...
_________________________
!

download KiXnet

Top
#144344 - 2005-07-27 02:52 AM Re: Finding full path to homedirectory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
for adsi, try this:
Code:

for each $share in GetObject("WinNT://"+@wksta+"/LanmanServer")
$share.name " " $share.path ?
next
get $

_________________________
!

download KiXnet

Top
#144345 - 2005-07-27 04:47 AM Re: Finding full path to homedirectory
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
Thanks for that wonderful help.

I've given up worrying about all I don't know and eagerly look forward to what i will learn. Will go and trial it and then put it into use.

Much appreciated.

Top
#144346 - 2005-07-27 07:46 AM Re: Finding full path to homedirectory
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
Thanks to your great thoughts, I found what I wanted and massaged the code to suit my needs. Once again, great service.

Code:

$strComputer = "."
$strNamespace = "\root\cimv2"
$strClassName = "Win32_Share"
$strKeyName = "Name"
$strKeyValue = "sillykid$"

$objSWbemServices = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $strComputer + $strNamespace)
$objInstance = $objSWbemServices.Get($strClassName + "." + $strKeyName + "='" + $strKeyValue + "'")
? $objInstance.path


Top
#144347 - 2005-07-27 08:20 AM Re: Finding full path to homedirectory
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
Question. Why do you want or need the actual path? Why isn't the servername\sillykid$ good enough?

Is this for one user only? For multiple computers reading a list and operating against it would be faster and seemingly more useful than a one machine call. You could have went into the GUI and found that info just as quick for one machine.
 

Top
#144348 - 2005-07-27 10:36 AM Re: Finding full path to homedirectory
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
Why do I want this? Hmmm... Long story.

At various stages in the school year I place AD users who have left (and even whole OU) in a storage OU called "DeleteMeLater". I've found that if I use Active Directory Users and Containers in my Console to delete these users then i have a terrible job finding their homedirs which don't get wiped when they are wiped. Also, occassionally, I find homedirs can't be removed from the server even manually. For example, I've got two such folders that give @error = 9 when I script their deletion.

So, I'm building a Kixform which allows me to:
1. loops through all users in DeleteMeLater and move their homedirs into a special folder so they are in one place.
2. delete each user in DeleteMeLater
3. delete each homedir
4. log any errors
5. Place troublesome homedirs in a folder marker "PigsOfThings" ... or something less polite

If you think there is a much better solution I'd love to know.

Top
#144349 - 2005-07-27 11:01 AM Re: Finding full path to homedirectory
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
Yeah, script the whole move and removal process.

Late here tonight, but I'm sure either as I get time or as other members here pitch in we can help you to automate the whole process better.

1. Disable the accounts of users who have left
2. Unshare their folder
3. Move their folder to some folder like OBSOLETE_ACCOUNTS
4. Run a script that checks the age of those folders and after say 30 days or some date you feel comfortable with, then have the script confirm the account is still there and delete the account including the mailbox, then have it delete the folder and files.


The entire thing should be able to be automated by a script that runs either on schedule and maybe reads a .INI file to determine what action to take against what account.

 

Top
#144350 - 2005-07-27 02:52 PM Re: Finding full path to homedirectory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
not sure about that fully automated.
if this process is done once a year, I think his approach with a slick KF stuff could be lot cooler
_________________________
!

download KiXnet

Top
#144351 - 2005-07-27 07:32 PM Re: Finding full path to homedirectory
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
Well not 100% automated, he still has to manually enter in who has left

But after that either a fully automated unseen script, or a KiXform should be quite doable.
 

Top
#144352 - 2005-07-27 10:26 PM Re: Finding full path to homedirectory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
doable sure, but usefulness should take a rating too, don't you think?
_________________________
!

download KiXnet

Top
#144353 - 2005-07-27 11:38 PM Re: Finding full path to homedirectory
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
Well we're starting to veer off topic so I'll let briannz556 decide if it's useful or not. I would think so if you cycle through hundreds of users every few months.
 

Top
#144354 - 2005-07-31 07:40 AM Re: Finding full path to homedirectory
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
Hi Guys
Script finished and works. Just testing and improving reporting. Only query now is about deleting mailboxes from Exchange 2000 server.

I've been reading the white paper "H:\My Documents\Kix Library\Server Tasks\research stuff\Automating Exchange 2000 Management with Windows Script Host.htm" and it seems that:

1. I must run my script from the exchange server if i'm to do all planned (remove share, delete mailbox, delete home directory and remove user). Correct?

2. Use CDOEXM to delete mailbox. Correct?

Happy to pursue (2) but just wondering if there are any previous queries on the board regarding mailbox creation/deletion using kix? I've searched but found nothing exactly relevant but maybe my eyes aren't as good as yours or query suitably constructed.

Once all complete I'm happy to post for others to use (some 400 - 500 lines). Is this acceptable?

Top
#144355 - 2005-07-31 05:26 PM Re: Finding full path to homedirectory
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22335
Loc: OK
1 - no, you can connect to exchange LDAP remotely as well.
_________________________
!

download KiXnet

Top
#144356 - 2005-08-08 01:31 AM Re: Finding full path to homedirectory
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
Back Again
I've completed all my tasks except for one: I need to allow for a corrupted homedirectory being unable to be deleted and which could be on a different server to that where the script is running.

My plan was to move the corrupted directory to a different spot on the same server where it exists. This is where I've been tearing my hair out. What is the best method to do such? Below is some trivial testing code. I've tried two options:

Option 1
Code:

$Computer = '.' ; local computer
$to = 'D:\Accounts\Corrupted Accounts\Rubbish'
$from = 'D:\Accounts\Rubbish'
$objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" + $Computer + "\root\cimv2")
? "Error= " + @ERROR + ' : ' + @SERROR + ' at point ' + '1'
$colFolders = $objWMIService.ExecQuery("SELECT * FROM Win32_Directory WHERE Name = '" + $from + "'")
? "Error= " + @ERROR + ' : ' + @SERROR + ' at point ' + '2'

For Each $objFolder in $colFolders
$result = $objFolder.Rename($to)
? "Error= " + @ERROR + ' : ' + @SERROR + ' at point ' + '3'
Next


but this returns an empty collection as the third error line never appears and the folder doesn't get moved.

Option 2 (which works)
Code:

$objFSO = CreateObject("Scripting.FileSystemObject")
$to = 'D:\Accounts\Corrupted Accounts\Rubbish'
$from = 'D:\Accounts\Rubbish'
$objFSO.MoveFolder($from, $to)



I'd really like to know why Option 1 doesn't work. Also, can FSO be used to bind to a folder on another server? if so, how do you write to path to the folders when it is on another server?

Top
#144357 - 2005-08-08 07:33 AM Re: Finding full path to homedirectory
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11571
Loc: CA
Well if the folder is truely corrupted and can not be deleted then you won't be able to move it either. You should run CHKDSK (VOLUME) /F /R

Which should then repair any corruption and allow you to remove the folder.

Top
#144358 - 2005-08-08 11:08 AM Re: Finding full path to homedirectory
briannz556 Offline
Getting the hang of it

Registered: 2002-05-03
Posts: 64
Loc: new zealand
Move is not perhaps the best word. Rename visually moves the folder and is what I meant. I have such folders (not many I grant) eg error # 9 in ASE. CHCKDSK hasn't seemed to make any difference when i ran it at the start of the year.

But to get back to my query: is there a simple way to move/rename a folder on another server? If so, a thread would be greatly appreciated. If not, I'll change my design plan. Your expert thoughts would be much appreciated.

Thanks

Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Arend_, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 156 anonymous users online.
Newest Members
diefnet, Arogya, gkustra, emnipetro, Hirze
17644 Registered Users

Generated in 0.045 seconds in which 0.015 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org