Page 1 of 1 1
Topic Options
#88823 - 2002-10-23 05:13 PM Ping Ben Delaney - Rename user w/ADSI
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Ben, I noticed in your Network Manager Script that you haven't enabled 'Rename User' yet. This is actually a pretty simple thing to do with '.MoveHere.' Here is a sample from a 'Disable User' script I have. The 'dis_user.txt' is just a text file with usernames in it so I can batch the job.

code:
break on cls

$objDomain=GetObject("WinNT://@domain")

$logfile=@SCRIPTDIR+"\dis_user_log.txt"
$nul=open(1,$logfile,5)

$database=@SCRIPTDIR+"\dis_user.txt"
$nul=open(2,$database,2)
$user=readline(2)
do
$objUser=GetObject("WinNT://@domain/$user,user")
if @error
$nul=WriteLine(1, $user+" Invalid Username"+chr(13)+chr(10))
$user+" Invalid Username" ?
else
$objUser.Description=$objUser.Description+" (Disabled @date)"
$objUser.AccountDisabled=1
$objUser.SetInfo
; This line renames the user account.
$nul=$objDomain.MoveHere($objUser.ADsPath, "01_"+$objUser.Name)
if @error
$nul=WriteLine(1, $user+" Not disabled error encountered"+chr(13)+chr(10))
$user+" not disabled error encountered" ?
else
$nul=WriteLine(1, $user+" Disabled"+chr(13)+chr(10))
$user+" disabled" ?
endif
endif
$user=readline(2)
until @error
$nul=close(1)
$nul=close(2)
exit


Top
#88824 - 2002-10-23 07:23 PM Re: Ping Ben Delaney - Rename user w/ADSI
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
Chris,

I haven't gotten there yet. I knew rename and delete would be less involved. I should probably go ahead and get those two working as creating a new user will take some time. Creating a new user is much more involved because I have to set up a method to choose which OU to stick the user in. This is basically causing me to go ahead and work on an OU manipulation tool because I have to list the entire structure of the AD so the appropriate OU can be chosen from the list. I already have it so a user can be created, however it is created in the default OU and I would like the OU it's created in to be user-defined. This OU tool is my reason for requesting the TreeView in KixForms. I've got the ADSI code worked out, it's just the GUI part of it that I'm having trouble with at the moment since I cannot find a good way to display the AD structure. I'm trying to do it with ListViews for now, but any suggestions on that would be nice too.

I appreciate the code and I'll try to get rename and delete in there today.

Also, I appreciate any and all feedback on this tool. I can't gaurantee all suggestions will be implemented, but I'll try to make it as effective as possible.

-Ben
http://www.rgcweb.org:90

[ 23. October 2002, 19:34: Message edited by: Ben Dulaney ]

Top
#88825 - 2002-10-23 07:54 PM Re: Ping Ben Delaney - Rename user w/ADSI
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
In lieu of a treeview object for KiXforms, I wonder how this might work in the interim. I have no idea how this might work in an AD environment. Care to try it?

code:
$objShell = CreateObject("Shell.Application")
$objFolder = $objShell.BrowseForFolder(0, "Select a folder:", 0, 18)
$objFolderItem = $objFolder.Self
? $objFolderItem.Name
? $objFolderItem.Parent
? $objFolderItem.Path
? $objFolderItem.Size
? $objFolderItem.Type


Top
#88826 - 2002-10-23 08:14 PM Re: Ping Ben Delaney - Rename user w/ADSI
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Or was thinking that maybe you could use a ListBox configured to act like a directory tree. Maybe enumerate all the top-level containers into the list first, example:

[.]
[..]
Users
Computers

The if you doubled clicked on users, it would enumerate all the containers under that, example:

[.]
[..]
[EastSideUsers]
[WestSideUsers]
John.Smith
Jane.Doe

Think this is similar to Chris's suggestion ... and to be honest, the logic involved to make this happen would be complex, but not much more than what would have to be done with TreeViews ... they aren't any kind of relief for this type of process ... mostly see recursion involved with TreeViews anyways ...

-Shawn

[ps] Is there anyway we (I) can assist in this project Ben ? Any canned UDF's you can farm out for development, then include them back into your script. Imagine that if the parameters were carefully chosen, could just plus-and-play into your script.... just a thought.

Top
#88827 - 2002-10-23 08:57 PM Re: Ping Ben Delaney - Rename user w/ADSI
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
The line you supplied Chris worked like a champ. The user can now be renamed in my script. I'm moving on to deleting a user now.

As far as the GUI on the AD view...I thought about using 2 listboxes, but wanted to preserve knowledge of the overall location in AD. I think this may be accomplished through some fancy labeling, but we'll see what I can do.

In regards to assistance with this tool, I am coming to a close on the User Manager side of it, and the hardest part (I hope [Wink] ) of the OU tool will be the visual layout which must be solved in the User Manager. I don't think there is much in these two modules to divy out, however I will be working on more modules in the future and if anyone is interested in starting work on those, I will definitely show much enthusiasm for it. I am planning on adding a service management module (which I think I may have seen elsewhere on this board, or something close). I was also planning on adding a Shared Folders - Open File management module. I'm trying to create a comprehensive tool to manage our network with a layout designed to be efficient and effective. Other possible modules (not sure if any of these are doable) would be an Event Viewer, DHCP Manager, DNS Manager, Exchange Manager, and who knows what else.

In conclusion [Smile] , I must say this is the most helpful board I have ever been a part of and the biggest reason I pursue KiX with so much enthusiasm. Thanks to everybody that asks questions and contributes answers to this board, especially the moderators that put so much effort in making their forums such a valuable resource. I'm glad that I am able to play a small role in this process.

-Ben
http://www.rgcweb.org:90

Top
#88828 - 2002-10-23 10:00 PM Re: Ping Ben Delaney - Rename user w/ADSI
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
Deleting a user is now working. I will be working on the 'Create new user' option next, and then I will get to the email options. Does anyone know default behaviour when a user's object is deleted, is the mailbox deleted too? If not, where can one find the orphaned email account? The option of (not) deleting the mailbox will be added when I get to the email functions.

-Ben
http://www.rgcweb.org:90

[ 23. October 2002, 22:10: Message edited by: Ben Dulaney ]

Top
#88829 - 2002-10-24 02:59 PM Re: Ping Ben Delaney - Rename user w/ADSI
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Ben, My little Black Book on Exchange tells me that the Exchange account is not deleted when the user account is deleted.

[ 24. October 2002, 15:00: Message edited by: Chris S. ]

Top
#88830 - 2002-10-24 06:37 PM Re: Ping Ben Delaney - Rename user w/ADSI
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
I created a user w/mailbox and then deleted the account and chose to not delete the mailbox. I tried to find the mailbox, but without success. Any ideas on where that little account can be found? I'll do a bit of research to try to find out and post where it is if I find it.

Also, I have come to a solution on browsing an Active Directory structure. I'll post the code shortly for others to check out and critique. I'm working on the finishing touches of back-tracking the structure. The view consists of 2 ListBoxes. A label above keeps track of the current location in the directory.

If anyone is in a multiple-domain environment, I would be grateful for testing as I only have one domain to test against. I tried to account for multiple domains, but we'll see.

-Ben
http://www.rgcweb.org:90

Top
#88831 - 2002-10-24 08:46 PM Re: Ping Ben Delaney - Rename user w/ADSI
Bonji Offline
Starting to like KiXtart

Registered: 2001-09-28
Posts: 169
Loc: Virginia
I'm going to post the code to the OU browsing tool, but there is one problem I am working on atm. If you double-click the right window to open an item and you are currently sitting at the highest level view, then it will not pull in any values in the left window. Once you've gone forward in the structure, going back will take you one level back and fill in the data. Once 'Back' has been taken, this problem goes away.

[EDIT]: I fixed this problem. No bugs as far as I know. Code has been updated.

Dependencies: Kixforms 2.1.1
code:
BREAK ON
$OULOC = " / "

$OU_FORM = CreateObject("KiXtart.FORM")
$OU_FORM.CAPTION = "OU VIEW"
$OU_FORM.SCALEHEIGHT = 450
$OU_FORM.SCALEWIDTH = 530
$OU_FORM.CENTER

$lblOULocation = $OU_FORM.Label("Current Path: "+$OULOC)
$lblOULocation.HEIGHT = 38
$lblOULocation.WIDTH = 450
$lblOULocation.LEFT = 75
$lblOULocation.TOP = 10

$cmdOUBack = $OU_FORM.CommandButton("Back")
$cmdOUBack.HEIGHT = 19
$cmdOUBack.WIDTH = 60
$cmdOUBack.LEFT = 10
$cmdOUBack.TOP = 8
$cmdOUBack.OnClick = "cmdOUBack_Click()"

$lstOU1 = $OU_FORM.ListBox
$lstOU1.HEIGHT = 300
$lstOU1.WIDTH = 250
$lstOU1.LEFT = 10
$lstOU1.TOP = 60
$lstOU1.OnClick = "lstOU1_Click()"
$lstOU1.OnDblClick = "lstOU1_DblClick()"

$lstOU2 = $OU_FORM.ListBox
$lstOU2.HEIGHT = 300
$lstOU2.WIDTH = 250
$lstOU2.LEFT = 270
$lstOU2.TOP = 60
$lstOU2.OnDblClick = "lstOU2_DblClick()"

$cmdOUOK = $OU_FORM.CommandButton("OK")
$cmdOUOK.HEIGHT = 19
$cmdOUOK.WIDTH = 80
$cmdOUOK.LEFT = 165
$cmdOUOK.TOP = 390
$cmdOUOK.OnClick = "cmdOUOK_Click()"
$cmdOUOK.Default = 1

$cmdOUCancel = $OU_FORM.CommandButton("Cancel")
$cmdOUCancel.HEIGHT = 19
$cmdOUCancel.WIDTH = 80
$cmdOUCancel.LEFT = 285
$cmdOUCancel.TOP = 390
$cmdOUCancel.OnClick = "$$OU_FORM = Nothing"
$cmdOUCancel.Cancel = 1

$OU_FORM.SHOW
$POPULATE2 = "NO"
$GONEBACK = "NO"
$OUROOT = ""

$LDAP = GetObject("LDAP:")
FOR EACH $ELEMENT IN $LDAP
$lstOU1.AddItem($ELEMENT.NAME);(SUBSTR($ELEMENT.NAME,4,LEN($ELEMENT.NAME) - 3))
NEXT

WHILE $OU_FORM.VISIBLE
$=EXECUTE($OU_FORM.DoEvents)
$OU_FORM.REFRESH
LOOP
$LDAP = Nothing


FUNCTION cmdOUOK_Click()
ENDFUNCTION

FUNCTION lstOU1_Click()
IF $OUROOT = ""
$CNT = 1
FOR EACH $ELEMENT IN $LDAP
IF $ELEMENT.NAME = $lstOU1.TEXT
$OUPATH = $ELEMENT.ADSPATH
ENDIF
NEXT
$OUROOT1 = SPLIT($OUPATH,",")
WHILE $CNT <= UBOUND($OUROOT1)
$OUROOT = $OUROOT + $OUROOT1[$CNT] + ","
$CNT = $CNT + 1
LOOP
$CNT = 0
$OUROOT = SUBSTR($OUROOT,1,LEN($OUROOT) - 1)
ENDIF
IF $INDEX2 <> $lstOU1.ListIndex
$POPULATE2 = "NO"
$lstOU2.CLEAR
ENDIF
$INDEX2 = $lstOU1.ListIndex
IF $POPULATE2 = "NO"
DIM $TMPARRAY
$TMPARRAY = SPLIT($OUPATH,",")
IF $lstOU1.TEXT <> SUBSTR($TMPARRAY[0],8,LEN($TMPARRAY[0]))
$PASSVAR1 = $lstOU1.TEXT + ","
ELSE
$PASSVAR1 = ""
ENDIF
$PASSVAR2 = SUBSTR($OUPATH,8,LEN($OUPATH))
$LDAP = GetObject("LDAP://"+$PASSVAR1+$PASSVAR2)
FOR EACH $ELEMENT IN $LDAP
$lstOU2.AddItem($ELEMENT.NAME)
NEXT
$POPULATE2 = "YES"
ENDIF
ENDFUNCTION

FUNCTION lstOU1_DblClick()
DIM $TMPARRAY
$OULOC = $OULOC + $lstOU1.TEXT + " / "
$lblOULocation.CAPTION = "Current Path: "+$OULOC
$TMPARRAY = SPLIT($OUPATH,",")
IF $lstOU1.TEXT <> SUBSTR($TMPARRAY[0],8,LEN($TMPARRAY[0]))
$PASSVAR1 = $lstOU1.TEXT+","
ELSE
$PASSVAR1 = ""
ENDIF
$PASSVAR2 = SUBSTR($OUPATH,8,LEN($OUPATH))
$OUPATH="LDAP://"+$PASSVAR1+$PASSVAR2
$LDAP = GetObject($OUPATH)
$lstOU1.CLEAR
FOR EACH $ELEMENT IN $LDAP
$lstOU1.AddItem($ELEMENT.NAME)
NEXT
$lstOU2.CLEAR
$POPULATE2 = "NO"
ENDFUNCTION

FUNCTION lstOU2_DblClick()
DIM $TMPARRAY
$OULOC = $OULOC + $lstOU1.TEXT + " / " + $lstOU2.TEXT + " / "
$lblOULocation.CAPTION = "Current Path: "+$OULOC
$TMPARRAY = SPLIT($OUPATH,",")
IF $lstOU2.TEXT <> SUBSTR($TMPARRAY[0],8,LEN($TMPARRAY[0]))
$PASSVAR1 = $lstOU2.TEXT+","
ELSE
$PASSVAR1 = ""
ENDIF
$PASSVAR2 = $lstOU1.TEXT+","
IF $GONEBACK = "NO"
$PASSVAR3 = ""
$TMPARRAY=SPLIT($OUPATH,",")
$CNT = 1
$TOTCNT = UBOUND($TMPARRAY)
WHILE $CNT <= $TOTCNT
$PASSVAR3 = $PASSVAR3 + $TMPARRAY[$CNT] + ","
$CNT = $CNT + 1
LOOP
$PASSVAR3 = SUBSTR($PASSVAR3,1,LEN($PASSVAR3) - 1)
ELSE
$PASSVAR3 = SUBSTR($OUPATH,8,LEN($OUPATH))
ENDIF
$OUPATH="LDAP://"+$PASSVAR1+$PASSVAR2+$PASSVAR3
$LDAP = GetObject($OUPATH)
$lstOU1.CLEAR
FOR EACH $ELEMENT IN $LDAP
$lstOU1.AddItem($ELEMENT.NAME)
NEXT
$lstOU2.CLEAR
$POPULATE2 = "NO"
ENDFUNCTION

FUNCTION cmdOUBack_Click()
IF $OULOC = " / "
$OU_FORM.MsgBox("You are at the top of the structure.","Error")
ELSE
$GONEBACK = "YES"
$WRKOULOC = SPLIT($OULOC,"/")
$WRKOUPATH = ""
$WRKOULOC2 = ""
$TOTCNT = UBOUND($WRKOULOC) - 2
$CNT = 0
WHILE $CNT <= $TOTCNT
$WRKOULOC2 = $WRKOULOC2 + $WRKOULOC[$CNT] + "/"
$WRKOUPATH1 = $WRKOULOC[UBOUND($WRKOULOC) - $CNT - 2]
$WRKOUPATH2 = SUBSTR($WRKOUPATH1,2,LEN($WRKOUPATH1) - 2)
$WRKOUPATH = $WRKOUPATH + $WRKOUPATH2 + ","
$CNT = $CNT + 1
LOOP
$OULOC = $WRKOULOC2+" "
$OUPATH = "LDAP://"+SUBSTR($WRKOUPATH,1,LEN($WRKOUPATH) - 1) + $OUROOT
$lstOU1.CLEAR
$lstOU2.CLEAR
IF $OULOC = " / "
$LDAP = GetObject("LDAP:")
FOR EACH $ELEMENT IN $LDAP
$lstOU1.AddItem($ELEMENT.NAME)
NEXT
ELSE
$LDAP = GetObject($OUPATH)
FOR EACH $ELEMENT IN $LDAP
$lstOU1.AddItem($ELEMENT.NAME)
NEXT
ENDIF
$lblOULocation.CAPTION = "Current Path: "+$OULOC
$POPULATE2 = "NO"
ENDIF
ENDFUNCTION

I welcome any suggestions/comments on this.

-Ben
http://www.rgcweb.org:90

[ 24. October 2002, 21:03: Message edited by: Ben Dulaney ]

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 484 anonymous users online.
Newest Members
Sir_Barrington, batdk82, StuTheCoder, M_Moore, BeeEm
17886 Registered Users

Generated in 0.055 seconds in which 0.022 seconds were spent on a total of 12 queries. Zlib compression enabled.

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