[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 759
  • Last Modified:

dsquery through hta

I have the following comand that i run from a command line:

dsquery group -name "<group name>" | dsget group -members | dsget user -samid

What id like to do is to:

1) Create a hta that
a) performs the same function as that above command
b) has a text box where you can input the name of the group you wish to get the members from.
Any help greatly appreciated.
I have attached what i have attempted so far.
Im trying to get the output displayed in the DataArea of my hta, but no luck.
Plus im not even sure if this is running correctly with the run method.

<html>
<head>
<title>My AD Group Membership</title>
 
<HTA:APPLICATION 
     ID="Find A Group's Users"
     APPLICATIONNAME="Group's Users"
     SCROLL="yes"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="maximize"
>
</head>
 
<SCRIPT Language="VBScript">
 
Sub GetUsers
strComputer = "."
groupName = txt_groupname.Value
Set objShell = CreateObject("Wscript.Shell") 
dsquerycmd = "dsquery group -name &groupName | dsget group -members | dsget user -samid"
objShell.run dsquerycmd
Set objShell = Nothing 
 
End Sub
 
</SCRIPT>
 
 
<body>
Please enter an AD group name you wish to return the users for:<input type="text" id="txt_groupname" name="txt_groupname">
<input type="button" value="Get Users" name="run_button" onClick="GetUsers">
<p>
<span id = "DataArea"></span>
</body>
</html>

Open in new window

0
Simon336697
Asked:
Simon336697
  • 3
1 Solution
 
yehudahaCommented:
do the same thing just with vbscript
<HTML>
	<HEAD>
		<TITLE>Users Group Query HTA</TITLE>
		<HTA:APPLICATION 
  			ID="MyApp" 
			APPLICATIONNAME="Template"
			BORDER="thick"
			BORDERSTYLE="complex"
			CAPTION="yes"
			CONTEXTMENU="no"
			ICON="http://Your URL/your icon.ico"
			INNERBORDER="yes"
			MAXIMIZEBUTTON="yes"
			MINIMIZEBUTTON="yes"
			NAVIGABLE="no"
			SCROLL="no"
			SHOWINTASKBAR="yes"
			SINGLEINSTANCE="yes"
			SYSMENU="yes"
			VERSION="1.0"
			WINDOWSTATE="maximized"/>
	</HEAD>
	
	<SCRIPT Language="VBScript">
	Set objRootDSE = GetObject("LDAP://rootDSE")
strDomain = "LDAP://" & objRootDSE.Get("defaultNamingContext")
Sub Window_Onload
        strComputer = "."
        Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
        Set colItems = objWMIService.ExecQuery("Select * From Win32_DesktopMonitor")
        For Each objItem In colItems
            intHorizontal = objItem.ScreenWidth
            intVertical = objItem.ScreenHeight
        Next
        intLeft = (intHorizontal - 800) / 2
        intTop = (intVertical - 600) / 2
        window.resizeTo 800,600
        window.moveTo intLeft, intTop
    End Sub
 
Sub runscript
Set objGroup = GetObject("LDAP://" & FindGroupPath(MyTextBox.Value))
objGroup.GetInfo
arrMemberOf = objGroup.GetEx("member")
 
For Each strMember In arrMemberOf
   DataArea.InnerHTML = DataArea.InnerHTML & FindUserPath(strMember) & "<BR>"
Next
 
End Sub
 
Sub Clear
        DataArea.InnerHTML = ""
    End Sub
 
 
Function FindGroupPath(Group)
                                
        selectedProperties = "distinguishedName"
                                
        Set oCn = CreateObject("ADODB.Connection")
        Set oCmd = CreateObject("ADODB.Command")
        oCn.Provider = "ADsDSOObject"
        oCn.Open "Active Directory Provider"
        Set oCmd.ActiveConnection = oCn
        oCmd.Properties("Page Size") = 1000
        oCmd.Properties("Searchscope") = 2 
        oCmd.CommandText = "SELECT " & selectedProperties & " FROM '" & strDomain & "' WHERE objectCategory='group'AND samAccountName = '" & Group & "'"
                                
        Set oRS = oCmd.Execute
        Do Until oRS.EOF
                FindGroupPath = oRS.Fields(selectedProperties).Value
                oRS.MoveNext
        Loop
End Function
 
Function FindUserPath(User)
                                                
        selectedProperties = "samAccountName"
                                                
        Set oCn = CreateObject("ADODB.Connection")
        Set oCmd = CreateObject("ADODB.Command")
        oCn.Provider = "ADsDSOObject"
        oCn.Open "Active Directory Provider"
        Set oCmd.ActiveConnection = oCn
        oCmd.Properties("Page Size") = 1000
        oCmd.Properties("Searchscope") = 2 
        oCmd.CommandText = "SELECT " & selectedProperties & " FROM '" & strDomain & "' WHERE objectCategory='user' AND Distinguishedname = '" & User & "'"
                                                
        Set oRS = oCmd.Execute
        Do Until oRS.EOF
                FindUserPath = oRS.Fields(selectedProperties).Value
                oRS.MoveNext
        Loop
End Function
	</SCRIPT>
	
	<body>
 <input type="text" name="MyTextBox" size=40 value="Enter Group Name"><p>
    <input type="button" value="Run" name="run_button" onClick="runscript">
	 <input id=runbutton type="button" value="clear" onClick="clear">
    <p>
<Span ID = "DataArea"></Span>
</body>
</html>

Open in new window

0
 
Simon336697Author Commented:
Hi yeh, thanks so much mate for your expertise.
yeh,

Im getting the following errors when running <:(

Line 40 Char 9 (I think this is window.moveTo intLeft, intTop)
I commented this line out and it loaded without that error.

Also,

Line 44 Char 1 (Could not complete the operation due to error 80005000)
Set objGroup = GetObject("LDAP://" & FindGroupPath(MyTextBox.Value))

When I try and click on the Clear button, it doesnt clear the text in the text box, nor does the Run button execute.

Appreciate your help.
0
 
yehudahaCommented:
hey

still having problems ?
0
 
yehudahaCommented:
i guess not
thanks for the points
0
 
CGIAMETTACommented:
It looks like it has a great potential but it has errors and does not work.  Did either of you fix the errors to make it work?  if either of you did can you post the correct code here so all of the rest of us who see this posting can benifit from it.

Tony...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now