I've been playing around with ADSI edits, and started writing this. As of right now it specifically looks for OU's that contain "Users" or "Contractors" in the name of the OU.

Please check it out and let me know what you think. I do have one question, though. How do I pass a KIX variable through a string? Basically what I mean, is that in the "Value" section, if I type @USERID I want it to know that it should find the UserID for the object, and not just simply put in "@USERID", you follow?

Thanks!
Chris

Code:

Break On

$Hide = SetConsole("Hide")
$System = CreateObject("Kixtart.System")

Dim $ProgramReset

;KD START

;************* Form **************
$Form = $System.Form()
$Form.BackColor = 212,208,200
$Form.Height = 240
$Form.MaximizeBox = "False"
$Form.Text = "ADSI Edit"
$Form.Width = 500
$Form.Center()
;**************************************

;************* RootDSE **************
$RootDSE = $Form.Controls.GroupBox()
$RootDSE.BackColor = 212,208,200
$RootDSE.Enabled = "False"
$RootDSE.Height = 170
$RootDSE.Left = 5
$RootDSE.Text = ""
$RootDSE.Top = 5
$RootDSE.Width = 485
;**************************************

;************* Get_Info_Button **************
$Get_Info_Button = $Form.Controls.Button()
$Get_Info_Button.Height = 23
$Get_Info_Button.Left = 10
$Get_Info_Button.Text = "Get Info"
$Get_Info_Button.ToolTipText = "Search for the RootDSE"
$Get_Info_Button.Top = 180
$Get_Info_Button.Width = 75
$Get_Info_Button.OnClick = "GetOUs"
;**************************************

;************* Reset_Info_Button **************
$Reset_Info_Button = $Form.Controls.Button()
$Reset_Info_Button.Enabled = "False"
$Reset_Info_Button.Height = 23
$Reset_Info_Button.Left = 90
$Reset_Info_Button.Text = "Reset"
$Reset_Info_Button.ToolTipText = "Reset the application"
$Reset_Info_Button.Top = 180
$Reset_Info_Button.Width = 75
$Reset_Info_Button.OnClick = "ResetButton"
;**************************************

;************* Change_Button **************
$Change_Button = $Form.Controls.Button()
$Change_Button.Enabled = "False"
$Change_Button.Height = 23
$Change_Button.Left = 325
$Change_Button.Text = "Change"
$Change_Button.Top = 180
$Change_Button.Width = 75
$Change_Button.OnClick = "ChangeButton"
;**************************************

;************* Cancel_Button **************
$Cancel_Button = $Form.Controls.Button()
$Cancel_Button.Height = 23
$Cancel_Button.Left = 405
$Cancel_Button.Text = "Cancel"
$Cancel_Button.ToolTipText = "Quit without making changes."
$Cancel_Button.Top = 180
$Cancel_Button.Width = 75
$Cancel_Button.OnClick = "Quit()"
;**************************************

;************* Select_OU_Combo **************
$Select_OU_Combo = $RootDSE.Controls.ComboBox()
$Select_OU_Combo.DropDownStyle = 2
$Select_OU_Combo.DropDownWidth = 121
$Select_OU_Combo.Enabled = "False"
$Select_OU_Combo.Height = 21
$Select_OU_Combo.Left = 70
$Select_OU_Combo.Sorted = "True"
$Select_OU_Combo.Text = ""
$Select_OU_Combo.Top = 40
$Select_OU_Combo.Width = 405
$Select_OU_Combo.OnClick = "OUsSelected"
;**************************************

;************* Select_OU_Label **************
$Select_OU_Label = $RootDSE.Controls.Label()
$Select_OU_Label.BackColor = 212,208,200
$Select_OU_Label.Height = 23
$Select_OU_Label.Left = 10
$Select_OU_Label.Text = "Select OU:"
$Select_OU_Label.Top = 43
$Select_OU_Label.Width = 100
;**************************************

;************* RootDSE_TextBox **************
$RootDSE_TextBox = $RootDSE.Controls.TextBox()
$RootDSE_TextBox.Enabled = "False"
$RootDSE_TextBox.Height = 20
$RootDSE_TextBox.Left = 70
$RootDSE_TextBox.ReadOnly = "True"
$RootDSE_TextBox.TabStop = "False"
$RootDSE_TextBox.Text = ""
$RootDSE_TextBox.Top = 10
$RootDSE_TextBox.Width = 405
;**************************************

;************* RootDSE_Label **************
$RootDSE_Label = $RootDSE.Controls.Label()
$RootDSE_Label.BackColor = 212,208,200
$RootDSE_Label.Height = 23
$RootDSE_Label.Left = 10
$RootDSE_Label.Text = "RootDSE:"
$RootDSE_Label.Top = 13
$RootDSE_Label.Width = 100
;**************************************

;************* Attribute_Combo **************
$Attribute_Combo = $RootDSE.Controls.ComboBox()
$Attribute_Combo.DropDownStyle = 2
$Attribute_Combo.DropDownWidth = 121
$Attribute_Combo.Enabled = "False"
$Attribute_Combo.Height = 21
$Attribute_Combo.Left = 70
$Attribute_Combo.Sorted = "False"
$Attribute_Combo.Text = ""
$Attribute_Combo.Top = 70
$Attribute_Combo.Width = 405
$Attribute_Combo.OnClick = "AttributeSelected"
;**************************************

;************* Attribute_Label **************
$Attribute_Label = $RootDSE.Controls.Label()
$Attribute_Label.BackColor = 212,208,200
$Attribute_Label.Height = 23
$Attribute_Label.Left = 10
$Attribute_Label.Text = "Attribute:"
$Attribute_Label.Top = 73
$Attribute_Label.Width = 70
;**************************************

;************* Value_TextBox **************
$Value_TextBox = $RootDSE.Controls.TextBox()
$Value_TextBox.Enabled = "False"
$Value_TextBox.Height = 20
$Value_TextBox.Left = 70
$Value_TextBox.Text = ""
$Value_TextBox.Top = 100
$Value_TextBox.Width = 405
$Value_TextBox.OnTextChanged = "ValueSelected"
;**************************************

;************* Value_Label **************
$Value_Label = $RootDSE.Controls.Label()
$Value_Label.BackColor = 212,208,200
$Value_Label.Height = 23
$Value_Label.Left = 10
$Value_Label.Text = "Value:"
$Value_Label.Top = 103
$Value_Label.Width = 100
;**************************************

;KD END

Function RunApplication

$RootDSE_TextBox.Text = ""
$Select_OU_Combo.Clear()
$Select_OU_Combo.Enabled = "False"
$Get_Info_Button.Enabled = "True"
$Attribute_Combo.Enabled = "False"
$Attribute_Combo.Clear()
$Value_TextBox.Enabled = "False"
$Value_TextBox.Text = ""
$Reset_Info_Button.Enabled = "False"
$Change_Button.Enabled = "False"

GetAttributes

$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1

EndFunction

Function fnLDAPQuery($What,Optional $From,Optional $Filter,Optional $OrderBy,Optional $Scope,
Optional $User,Optional $Pswd)

Dim $oCon,$oCMD,$oRS,$sQ,$aR,$C,$R

$sQ="<"+IIf($From="","LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext"),
$From)+">;"+$Filter+";"+IIf(VarType($What)>8192,Join($What,','),$What)+";"+
IIf($Scope<>"base" And $Scope<>"onelevel","subtree",$Scope)

$oCon=CreateObject("ADODB.Connection")
$oCon.Provider="ADsDSOObject"
$oCon.Properties("Encrypt Password").Value=1
$oCon.Properties("ADSI Flag").Value=1
If $User And $Pswd
$oCon.Properties("User ID").Value=$User
$oCon.Properties("Password").Value=$Pswd
EndIf
$oCon.Open("Active Directory Provider")

$oCMD=CreateObject("ADODB.Command")
$oCMD.ActiveConnection=$oCon
$oCMD.CommandText=$sQ
$oCMD.Properties("Page Size").Value=1000
$oCMD.Properties("Timeout").Value=30
$oCMD.Properties("Cache Results").Value=0

If InStr($OrderBy,"distinguishedName")
$oRS=CreateObject("ADODB.Recordset")
$oRS.CursorLocation=3
$oRS.Sort=$OrderBy
$oRS.Open($sQ,$oCon,0,1,1)
Else
If $OrderBy
$oCMD.Properties("Sort On").Value=$OrderBy
EndIf
$oRS=$oCMD.Execute
EndIf
If @ERROR Exit @ERROR EndIf
If $oRS.BOF And $oRS.EOF Exit @ERROR EndIf

$aR = $oRS.GetRows()
Dim $aFR[Ubound($aR,2),Ubound($aR,1)]
For $R=0 to Ubound($aR,2)
For $C=0 to Ubound($aR,1)
$aFR[$R,$C]=$aR[$C,$R]
Next
Next

$fnLDAPQuery=$aFR
EndFunction

Function GetOUs
$sWhat = "distinguishedName"

$sFrom = "LDAP://"+GetObject("LDAP://rootDSE").Get("defaultNamingContext")

$sFilter = "(&(|(objectCategory=organizationalUnit))(&(|(name=Employees)(name=Contractors))))";)(!name=Desk*)(!name=Disabled)(!name=Groups)(!name=Printers))"

$sScope = "SubTree"

$aResults = fnLDAPQuery($sWhat,$sFrom,$sFilter,,$sScope)

For $c = 0 to Ubound($aResults)
$Select_OU_Combo.additem($aResults[$c,0])
Next

;Region Enable The Disabled
$RootDSE.Enabled = "True"
$Select_OU_Combo.Enabled = "True"
;EndRegion

$Get_Info_Button.Enabled = "False"
$Reset_Info_Button.Enabled = "True"
$RootDSE_TextBox.Text = "$sFrom"
EndFunction

Function OUsSelected
$RootDSE_TextBox.Text = "LDAP://" + $Select_OU_Combo.Text
$Attribute_Combo.Enabled = "True"
EndFunction

Function GetAttributes
Dim $objClass,$strAttribute

$objClass = GetObject("LDAP://schema/user")

For Each $strAttribute in $objClass.MandatoryProperties
$Attribute_Combo.additem($strAttribute)
Next

; Optional attributes
For Each $strAttribute in $objClass.OptionalProperties
$Attribute_Combo.additem($strAttribute)
Next
EndFunction

Function AttributeSelected
$Value_TextBox.Enabled = "True"
EndFunction

Function ResetButton
RunApplication
EndFunction

Function ValueSelected
If $Value_TextBox.Text = ""
$Change_Button.Enabled = "False"
Else
$Change_Button.Enabled = "True"
EndIf
EndFunction

Function ChangeButton
$UserObj = GetObject("LDAP://" + $Select_OU_Combo.Text)
$UserObj.Filter = Split('user')
$Count = 0

For Each $User in $UserObj
$Count = $Count + 1
Next

$Selection = MessageBox("You are about to change " + $Count + " accounts, are you sure you want to continue?","Notice",4132)

If $Selection = 6
$Change_Attribute = $Attribute_Combo.Text
$Change_Value = $Value_TextBox.Text
$Count = 0
$msg = MessageBox($Change_Attribute + " " + $Change_Value,"Notice",48)
For Each $User in $UserObj
;$User.put($Change_Attribute,$Change_Value)
;$User.setinfo
$Count = $Count + 1
Next
$msg = MessageBox("A total of " + $Count + " addresses have been changed!","Notice",4144)
EndIf
ResetButton
EndFunction


RunApplication