KiXforms Forum Index KiXforms
The Forum for the KiXforms Community
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Quick Links 
Site News
Downloads
Documentation
Donations
Script Archive
Tracking Systems

Retrive a users distinguishedname with just a full name

 
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive
View previous topic :: View next topic  
Author Message
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Wed Aug 18, 2004 12:25 am    Post subject: Retrive a users distinguishedname with just a full name Reply with quote

Here is a AD UDF that I use to pull a users distinguishedName.
Very handy for many scripts, I have used this in scripts to force a password change, edit user(s), for a single user, groups, as well as entire domains.

Code:

;sample call
GetUserdistinguishedName(Test User,TestDomain)
? $UserdistinguishedName

Function GetUserdistinguishedName($FullName,$Doamin)
   
   $ADS_UF_ACCOUNTDISABLE = 2
   
   $objConnection = CreateObject("ADODB.Connection")
   $objConnection.Open("Provider=ADsDSOObject;")
   $objCommand = CreateObject("ADODB.Command")
   $objCommand.ActiveConnection = $objConnection
   $objCommand.CommandText = "<GC://dc=" + $Doamin + ",dc=com>;(objectCategory=User);userAccountControl,distinguishedName;subtree"
   $objRecordSet = $objCommand.Execute
   While NOT $objRecordset.EOF
      $Positive = InStr($objRecordset.Fields("distinguishedName"),"CN=" + $FullName)
      If $Positive <> 0
         $objUser = GetObject("LDAP://" + $objRecordset.Fields("distinguishedName"))
         $objUser.GetInfo
         $UserdistinguishedName = $objUser.Get("distinguishedName")
      EndIf
      $objRecordset.MoveNext
   Loop
   $objConnection.Close
   
EndFunction



Tell me what you think?

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Les
KiXforms Aficionado
KiXforms Aficionado


Joined: 24 Dec 2003
Posts: 317

PostPosted: Wed Aug 18, 2004 2:11 am    Post subject: Reply with quote

I think there is no form.
_________________
The Repro Man
Stealing for a living!
Back to top
View user's profile Send private message
Jochen
KiXforms Devotee
KiXforms Devotee


Joined: 05 Mar 2003
Posts: 1204
Location: Stuttgart, Germany

PostPosted: Wed Aug 18, 2004 6:11 am    Post subject: Reply with quote

Benny,

please feel invited to post this over here : Korg UDF Library

You might get much more feedback there

_________________
Jochen

Tell me, and I will forget.
Show me, and I may remember.
Involve me, and I will understand.
Back to top
View user's profile Send private message MSN Messenger
benny69
KiXforms Advocate
KiXforms Advocate


Joined: 30 Oct 2003
Posts: 567
Location: Lincoln, Ne

PostPosted: Wed Aug 18, 2004 12:15 pm    Post subject: Reply with quote

Opps, I was planning on posting this with the first. Sorry.

Code:
Global $Doamin
$Doamin = @DOMAIN

Break on

$system = CreateObject("kixtart.system")

$form = $system.form()
$form.font = $system.font("verdana",10)
$form.text = "Force a Password Change"
$form.size = 415,350
$form.Center
For $k = 0 to 107
   $ = $form.SmallImageList.Images.Add("shell32.dll;"+$k)   ;68 - 175
Next
$form.Icon = $System.BuiltinIcons(85)

$menu = $system.mainmenu()
$filemenu = $menu.menuitems.add("File")
$exitmenu = $filemenu.menuitems.add("Exit")
$exitmenu.onclick = "quit()"

$editmenu = $menu.menuitems.add("Edit")
$Forcemenu = $editmenu.menuitems.add("Force Password Change")
$Forcemenu.onclick = "ForceChange()"

$form.menu = $menu

$EditDomainUserListGroupBox = $form.GroupBox("Edit Domain User List",5,5,400,270)
$EditDomainUserListBoxLabel = $EditDomainUserListGroupBox.Controls.Label("Domain User List:",5,20,100,15)

$EditDomainUserListBox = $EditDomainUserListGroupBox.Controls.ListBox("",5,40,170,186)
$EditDomainUserListBox.Sorted = "True"
$EditDomainUserListBox.TabStop = "True"
$EditDomainUserListBox.OnDoubleClick = "AddToSelectedDomainUserListBox()"

$EditDomainUserAddAllButton = $EditDomainUserListGroupBox.Controls.Button(">>",185,77,33,25)
$EditDomainUserAddAllButton.TabStop = "True"
$EditDomainUserAddAllButton.OnClick = "AddAllToSelectedDomainUserListBox()"

$EditDomainUserAddButton = $EditDomainUserListGroupBox.Controls.Button(">",185,107,33,25)
$EditDomainUserAddButton.TabStop = "True"
$EditDomainUserAddButton.OnClick = "AddToSelectedDomainUserListBox()"

$EditDomainUserRemoveButton = $EditDomainUserListGroupBox.Controls.Button("<",185,137,33,25)
$EditDomainUserRemoveButton.TabStop = "True"
$EditDomainUserRemoveButton.OnClick = "RemoveFromSelectedDomainUserListBox()"

$EditDomainUserRemoveAllButton = $EditDomainUserListGroupBox.Controls.Button("<<",185,167,33,25)
$EditDomainUserRemoveAllButton.TabStop = "True"
$EditDomainUserRemoveAllButton.OnClick = "RemoveAllFromSelectedDomainUserListBox()"

$SelectedDomainUserListBoxLabel = $EditDomainUserListGroupBox.Controls.Label("Selected Domain User(s) List:",225,20,170,15)
$SelectedDomainUserListBox = $EditDomainUserListGroupBox.Controls.ListBox("",225,40,170,186)
$SelectedDomainUserListBox.Sorted = "True"
$SelectedDomainUserListBox.TabStop = "True"
$SelectedDomainUserListBox.OnDoubleClick = "RemoveFromSelectedDomainUserListBox()"

$EditDomainUserButton = $EditDomainUserListGroupBox.Controls.Button("Force Password Change",120,235,175,23)
$EditDomainUserButton.TabStop = "True"
$EditDomainUserButton.OnClick = "ForceChange()"

$Statusbar = $form.statusbar()
$Statusbar.dock = "bottom"

$StatusbarLabel = $Statusbar.Controls.Label("",3,4,268,19)
$StatusbarLabel.BorderStyle = 2

$ProgressBar = $Statusbar.Controls.ProgressBar("",274,4,100,19)
$ProgressBar.Maximum = 100
$ProgressBar.Minimum = 0
$ProgressBar.Style = 1
$ProgressBar.Step = 1

ProgressBar()

Function ProgressBar()

   Break On
   
   $frmForm = CreateObject("Kixtart.Form")
   $frmForm.Width = 320
   $frmForm.Height = 110
   $frmForm.Caption = "Loading Domain Users"
   $frmForm.Center
   
   For $k = 0 to 107
      $ = $form.SmallImageList.Images.Add("shell32.dll;"+$k)   ;68 - 175
   Next
   $frmForm.Icon = $System.BuiltinIcons(85)
   
   $prgProgressBarLable = $frmForm.label("",10,20,294,20)
   $prgProgressBar1 = $frmForm.ProgressBar("",10,50,294,20)
   $prgProgressBar1.Style = 1
   
   $frmForm.Show
   
   PopulateEditDomainUserList()
   $Count = 0
   $prgProgressBar1.Value = 0
   

   $frmForm.Hide
   Exit

EndFunction

Function AdvanceProgressBar1($Step,$Text)

   $Count = $Count + $Step
   If $Count > 100
      $Count = 0
   EndIf
   $prgProgressBarLable.text = $Text
   $prgProgressBar1.Value = $Count
   
   Sleep 0.05

EndFunction

$form.show()
While $form.visible
   $= Execute($form.doevents)
Loop

Exit 1

Function PopulateEditDomainUserList()
   
   $objDomain = GetObject("WinNT://" + $Doamin + ",domain")
   
   For Each $User In $objDomain
     If $User.Class = "User"
         If $User.fullname <> ""
            $EditDomainUserListBox.AddItem($User.fullname)
            AdvanceProgressBar1(1,$User.fullname)
         EndIf
     EndIf
   Next
   
   $objDomain = 0
   
EndFunction

Function AddAllToSelectedDomainUserListBox()

   $SelectedDomainUserListBox.Clear
   For $x = 0 to $EditDomainUserListBox.ListCount
      If $EditDomainUserListBox.List($x) <> ""
         $SelectedDomainUserListBox.AddItem($EditDomainUserListBox.List($x))
      EndIf
   Next
   
EndFunction

Function AddToSelectedDomainUserListBox()
   
   $ListItem = "No"
   For $x = 0 to $SelectedDomainUserListBox.ListCount
      If $SelectedDomainUserListBox.List($x) = $EditDomainUserListBox.Text
         $ListItem = "Yes"
      EndIf
   Next
   If $ListItem = "No"
      $SelectedDomainUserListBox.AddItem($EditDomainUserListBox.Text)
   EndIf
   
EndFunction

Function RemoveFromSelectedDomainUserListBox()
   
   $SelectedDomainUserListBox.RemoveItem($SelectedDomainUserListBox.ListIndex)

EndFunction

Function RemoveAllFromSelectedDomainUserListBox()

   $SelectedDomainUserListBox.Clear

EndFunction

Function ForceChange()
   
   For $x = 0 to $SelectedDomainUserListBox.ListCount
      $FullName = $SelectedDomainUserListBox.List($x)
      If $FullName <> ""
         GetUserdistinguishedName($FullName)
      EndIf
   Next
   $SelectedDomainUserListBox.Clear
   $StatusbarLabel.text = "Done"
   $ProgressBar.Value = 0
   
EndFunction

Function GetUserdistinguishedName($FullName)
   
   $StatusbarLabel.text = "Pulling " + $FullName + " distinguishedName"
   $ADS_UF_ACCOUNTDISABLE = 2
   
   $objConnection = CreateObject("ADODB.Connection")
   $objConnection.Open("Provider=ADsDSOObject;")
   $objCommand = CreateObject("ADODB.Command")
   $objCommand.ActiveConnection = $objConnection
   $objCommand.CommandText = "<GC://dc=" + $Doamin + ",dc=com>;(objectCategory=User);userAccountControl,distinguishedName;subtree"
   $objRecordSet = $objCommand.Execute
   While NOT $objRecordset.EOF
      If $FullName <> ""
         $Positive = InStr($objRecordset.Fields("distinguishedName"),"CN=" + $FullName)
         If $Positive <> 0
            $objUser = GetObject("LDAP://" + $objRecordset.Fields("distinguishedName"))
            $objUser.GetInfo
            $UserdistinguishedName = $objUser.Get("distinguishedName")
            $StatusbarLabel.text = "Force Change for: " + $FullName
            ForcePasswordChange($UserdistinguishedName)
            $Positive = 0
            $FullName = ""
         EndIf
      EndIf
      $objRecordset.MoveNext
   Loop
   $objConnection.Close
   
EndFunction

Function ForcePasswordChange($UserdistinguishedName)   

   $User = GetObject("LDAP://" + $UserdistinguishedName)

   $User.Put ("userAccountControl", 512)
   $User.Put ("pwdLastSet", 180)

   $User.SetInfo
   
   changeProgressbar(10)
   
EndFunction

Function changeProgressbar($Step)
   
   $Count = $Count + $Step
   If $Count > 100
      $Count = 0
   EndIf
   $ProgressBar.Value = $Count
   
EndFunction



Thats better...

_________________
Wait don't order yet,... get KiXforms Designer .NET 2.0 (Beta)
KiXforms Designer .NET 2.0 (Beta)
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    KiXforms Forum Index -> Script Archive All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group