#144339 - 2005-07-27 01:44 AM
Finding full path to homedirectory
|
briannz556
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
|
|
|
|
#144341 - 2005-07-27 02:41 AM
Re: Finding full path to homedirectory
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
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
|
|
|
|
#144345 - 2005-07-27 04:47 AM
Re: Finding full path to homedirectory
|
briannz556
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
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
|
|
|
|
#144348 - 2005-07-27 10:36 AM
Re: Finding full path to homedirectory
|
briannz556
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
|
|
|
|
#144351 - 2005-07-27 07:32 PM
Re: Finding full path to homedirectory
|
NTDOC
Administrator
Registered: 2000-07-28
Posts: 11623
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
|
|
|
|
#144354 - 2005-07-31 07:40 AM
Re: Finding full path to homedirectory
|
briannz556
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
|
|
|
|
#144356 - 2005-08-08 01:31 AM
Re: Finding full path to homedirectory
|
briannz556
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
|
|
|
|
#144358 - 2005-08-08 11:08 AM
Re: Finding full path to homedirectory
|
briannz556
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
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
1 registered
(Allen)
and 382 anonymous users online.
|
|
|