|
aboren -> RE: Task Sequence – ADSI Script (10/8/2008 4:56:50 AM)
|
Hi, got some code 4 ya. Ive made a "better" OU list creation if you got more OUs then the one Johan A have released. Use the functions combined to create your OU list & then hook it to your HTA listbox name. Then set a TaskSequence Variable (code for this exists in the MS supplied UnknownComputer.hta) eg. TSvar_OUtojoin with the value from the listbox you have choosen. Inside your TaskSequense at the step where you join a domain, type %TSvar_OUtojoin% in the OU field. Replace the domain/account, password, ldap path & strBaseOUConnString with your Values/variables. (There may be missing declarations & variables for you, my script is VERY massive in total so i tried to rewrite this part as Transparent as i could.)
Sub GetOUList
'Option Explicit
Dim strBaseOUConnString
Dim objOULevel
Dim OUintLevel
Dim objRootDSE
Dim OpenOU
Const ADS_SECURE_AUTHENTICATION = &H0001
Const ADS_SERVER_BIND = &H0200
Set OpenOU = GetObject("LDAP:")
strBaseOUConnString = "ou=computers,ou=resources,dc=domain,dc=com"
Set objOULevel = OpenOU.OpenDSObject("LDAP://server.domain.com/" & strBaseOUConnString & "", "domain\account", "PASSWORD", ADS_SECURE_AUTHENTICATION + ADS_SERVER_BIND)
objOULevel.Filter = Array("OrganizationalUnit")
GetOURecurse objOULevel, 0, strBaseOUConnString
End Sub
Function GetOURecurse(objOU, OUXLevel, strBaseConn)
Dim objOUObject, strConnString, objActiveOption, ldapQ, OpenSesame, objDefOption, objremOUdOption
Const ADS_SA = &H0001
Const ADS_SB = &H0200
If defOUnr = 0 Then
For Each objremOUdOption In OUDropdown.Options'The referenced Listbox in your HTA
objremOUdOption.removeNode
Next
Set objDefOption = Document.CreateElement("OPTION")
objDefOption.Text = "----- Pick Destination OU -----"
objDefOption.Value = "9999"
OUDropdown.Add objDefOption
OUDropdown.value = "9999"
End If
defOUnr = 1
Set OpenSesame = GetObject("LDAP:")
For Each objOUObject In objOU
If UCase(Left(objOUObject.Name, 3)) = "OU=" Then
strConnString = objOUObject.DistinguishedName
Set objActiveOption = Document.CreateElement("OPTION")
If OUXLevel = 0 Then
objActiveOption.Text = Replace(objOUObject.Name, "OU=", "")
Else
objActiveOption.Text = String(OUXLevel * 4, " ") & "-> " & Replace(objOUObject.Name, "OU=", "")
End If
objActiveOption.Value = strConnString
OUDropdown.Add objActiveOption
Set ldapQ = OpenSesame.OpenDSObject("LDAP://server.domain.com/" & strConnString & "", "domain\account", "PASSWORD", ADS_SA + ADS_SB)
ldapQ.Filter = Array("OrganizationalUnit")
GetOURecurse ldapQ, OUXLevel + 1, strBaseConn
End If
Next
End Function
My codeblock for adding the TSvariable, setting the OU to join variable. (Requires alot more, but its all in the MS$ provided UnknownComputer.hta found in the SDK)
If AddToOU = "True" Then
Log ("Creating Task sequence variable OSDDomainOUName" )
' TS variable "OSDDomainOUName" is used as variable in the OU field at "Apply Network Settings"
returnVal = SetTSVar ("OSDDomainOUName", JoinarOU)
Sleep (5000)
If returnVal <> 0 Then
Log ("Failed to set TS Variable OSDDomainOUName code: " & returnVal & ".")
StatusInfo ("ERROR - Check the Log.")
logFileSystemObject.Close
logFileSystemObject = null
Main = returnVal
Exit Function
End If
|
|
|
|