bsharath
asked on
Hta file that shows the Security groups in a dropdown menu of a particular OU. When selected asks for the users to be added.
Hi,
Hta file that shows the Security groups in a dropdown menu of a particular OU. When selected asks for the users to be added.
So when needed a user can add the users he wants.
A box that takes the users Nt logins with a ; as the sepeartor and add's the users to the groups. Is there any script Hta that can do this...
Regards
Sharath
Hta file that shows the Security groups in a dropdown menu of a particular OU. When selected asks for the users to be added.
So when needed a user can add the users he wants.
A box that takes the users Nt logins with a ; as the sepeartor and add's the users to the groups. Is there any script Hta that can do this...
Regards
Sharath
Try this.
Enter the OU which contains the groups on line 17;
strOU = "OU=XYZ,DC=DOMAIN,DC=COM"
Enter the domain name containing the users on line 20;
strDomain = "DOMAIN"
Enter the OU which contains the groups on line 17;
strOU = "OU=XYZ,DC=DOMAIN,DC=COM"
Enter the domain name containing the users on line 20;
strDomain = "DOMAIN"
<head>
<title>User Information</title>
<HTA:APPLICATION
APPLICATIONNAME="User Information"
BORDER="thin"
SCROLL="yes"
SINGLEINSTANCE="yes"
ID="oHTA"
>
<APPLICATION:HTA>
</head>
<script language="VBScript">
Dim strOU, strDomain
'Enter the OU you want to get groups from
strOU = "OU=XYZ,DC=DOMAIN,DC=COM"
'Enter the domain name where the users can be found
strDomain = "DOMAIN"
Sub Window_OnLoad
FillGroupMembershipList
End Sub
Sub FillGroupMembershipList
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
strSearchField = "(distinguishedname=*)"
strBase = "<LDAP://" & strOU & ">"
strFilter = "(&(objectCategory=group)" & strSearchField & ")"
strAttributes = "cn,distinguishedName,primaryGroupID,samaccounttype"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
adoCommand.Properties("Sort On") = "cn"
Set adoRecordset = adoCommand.Execute
If Not adoRecordset.EOF Then
Do Until adoRecordset.EOF
strNTName = adoRecordset.Fields("cn").Value
strGroupType = adoRecordset.Fields("samaccounttype").Value
strPrimary = adoRecordset.Fields("primaryGroupID").Value
strdistinguishedName = adoRecordset.Fields("distinguishedname").Value
Select Case strGroupType
Case -2147483646, 268435456 'This is a global security group
set newOption = document.createElement("OPTION")
newOption.Text = strNTName
newOption.Value = strPrimary & ";" & strdistinguishedName
lst_groupnames.Add newOption
Case -2147483644, 536870912 'This is a domain local security group
set newOption = document.createElement("OPTION")
newOption.Text = strNTName
newOption.Value = strPrimary & ";" & strdistinguishedName
lst_groupnames.Add newOption
Case -2147483640, 268435456 'This is a universal security group
set newOption = document.createElement("OPTION")
newOption.Text = strNTName
newOption.Value = strPrimary & ";" & strdistinguishedName
lst_groupnames.Add newOption
End Select
adoRecordset.MoveNext
Loop
End If
adoRecordset.Close
Set adoRecordset = Nothing
adoConnection.Close
End Sub
Sub Submit_Form
on error resume next
strUserNames = txt_usernames.Value
if strUserNames = "" then
msgbox "Cannot proceed - please input user name(s)"
else
For i = 0 to (lst_groupnames.Options.Length - 1)
If (lst_groupnames.Options(i).Selected) Then
arrGroupNames = split(lst_groupnames.Options(i).Value,";")
strprimaryGroupID = arrGroupNames(0)
strGroupDN = arrGroupNames(1)
End If
Next
arrUserNames = split(strUserNames,";")
for each strUser in arrUserNames
strUser = trim(strUser)
strUserDN = GetDistinguishedNameofUser(strUser)
if strUserDN <> "" then
Set objUser = GetObject("LDAP://"& strUserDN)
Set objGroup = GetObject("LDAP://"& strGroupDN)
objGroup.add(objUser.ADsPath)
else
msgbox "Error: Could not find """ & strUser & """"
end if
next
End if
txt_usernames.Value = ""
msgbox "Done."
End Sub
Function GetDistinguishedNameofUser(Name)
on error resume next
Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection
strSearchField = "(SAMAccountName=" & Name & ")"
strBase = "<LDAP://" & strDomain & ">"
strFilter = "(&(objectCategory=user)" & strSearchField & ")"
strAttributes = "distinguishedName"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
adoCommand.CommandText = strQuery
adoCommand.Properties("Page Size") = 100
adoCommand.Properties("Timeout") = 30
adoCommand.Properties("Cache Results") = False
Set adoRecordset = adoCommand.Execute
strdistinguishedName = adoRecordset.Fields("distinguishedname").Value
GetDistinguishedNameofUser = strdistinguishedName
End Function
</script>
<body>
<table border="0" padding="1">
<tr><td>Security Groups:</td><td></td><td><select id="lst_groupnames" name="lst_groupnames"></select></td></tr>
<tr><td>Users to add:</td><td></td><td><input type="text" size="50" id="txt_usernames" name="txt_usernames"></td></tr>
<tr><td colspan="2"><input type="submit" value="Submit" name="btn_submit" onClick="vbs:Submit_Form"></td></tr>
</table>
</body>
ASKER
Thank Rejoinder works great...
Additions please.
1. A Drop down for distribution groups also.
2. Can we have the script if wanted to search the whole domain and root only to get the groups. Like you did in the other HTA.
Only one OU or both Domains. if i can have both options that would be useful...
Additions please.
1. A Drop down for distribution groups also.
2. Can we have the script if wanted to search the whole domain and root only to get the groups. Like you did in the other HTA.
Only one OU or both Domains. if i can have both options that would be useful...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank U
Works fine....
This is yet another Awesome help....
Works fine....
This is yet another Awesome help....
ASKER
Hi Rejoinder...need your help please...
https://www.experts-exchange.com/questions/24932541/Hta-script-from-Rejoinder-Need-a-addition.html
https://www.experts-exchange.com/questions/24932541/Hta-script-from-Rejoinder-Need-a-addition.html
ASKER