?
Solved

HTA Script - DSQuery

Posted on 2012-03-14
7
Medium Priority
?
1,468 Views
Last Modified: 2013-12-24
Hi Experts,

Can you help me for HTA script for the below query:

dsquery * "CN=Sites,CN=Configuration,DC=nestle,DC=com" -filter "&(objectcategory=site)(name=CHENNAI-SITE)" -attr siteObjectBL description distinguishedName whenCreated whenChanged

The above query will give the result. But my aim to have that done in HTA script.

HTA Script:

Input Will be site name = CHENNAI-SITE
Output should give:

siteObjectBL
description
distinguishedName
whenCreated
whenChanged

HTA script will be great for me.

Any questions, please let me know.

Thanks,
Prem
0
Comment
Question by:Premkumar Yogeswaran
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 65

Expert Comment

by:RobSampson
ID: 37723491
Hi there,

See if this works.

Regards,

Rob.

<head>
<title>Active Directory Site Information</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Active Directory Site Information"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
</head>

<script language="VBScript">

Sub Window_onLoad
	intWidth = 800
	intHeight = 600
	Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
    lstResults.Style.Width = 300

		 ' Search entire Active Directory domain.
		Set adoCommand = CreateObject("ADODB.Command")
		Set adoConnection = CreateObject("ADODB.Connection")
		adoConnection.Provider = "ADsDSOObject"
		adoConnection.Open "Active Directory Provider"
		adoCommand.ActiveConnection = adoConnection

		Set objRootDSE = GetObject("LDAP://RootDSE")
		
		strDNSDomain = objRootDSE.Get("defaultNamingContext")
		strBase = "<LDAP://" & strDNSDomain & ">"
		
		strFilter = "(&(objectcategory=site))"
		
		' Comma delimited list of attribute values to retrieve.
		strAttributes = "name,distinguishedName"
		
		' Construct the LDAP syntax query.
		strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
		adoCommand.CommandText = strQuery

		adoCommand.Properties("Page Size") = 100
		adoCommand.Properties("Timeout") = 30
		adoCommand.Properties("Cache Results") = False
		
		' Run the query.
		Set adoRecordset = adoCommand.Execute
		 
		' Enumerate the resulting recordset.
		Do Until adoRecordset.EOF
		    ' Retrieve values and display.
			Set objNewOption = Document.CreateElement("OPTION")
			objNewOption.Text = adoRecordset.Fields("name").Value
			objNewOption.Value = adoRecordset.Fields("distinguishedName").Value
			lstResults.Add(objNewOption)
		    ' Move to the next record in the recordset.
		    adoRecordset.MoveNext
		Loop
		
		' Clean up.
		adoRecordset.Close
		Set adoRecordset = Nothing
		
		adoConnection.Close
		Get_Details
End Sub

Sub Get_Details
	On Error Resume Next
	Set objObject = GetObject("LDAP://" & lstResults.Value)
	txt_siteobjectbl.Value = objObject.siteobjectBL
	txt_description.Value = objObject.description
	txt_dn.Value = objObject.distinguishedName
	txt_whencreated.Value = objObject.whenCreated
	txt_whenchanged.Value = objObject.whenChanged
	Err.Clear
	On Error GoTo 0
End Sub

</script>

<body STYLE="background-color:#B0C4DE; font-family: arial">
	<table width='90%' height = '90%' align='center' border='0'>
		<tr>
			<td colspan="4" align="center">
				<h2>
					Active Directory Site Information
				</h2>
			</td>
		</tr>
		<tr>
			<td align='center' colspan="2">
				Choose a Site Name:
				<select size='1' name='lstResults' onchange="vbs:Get_Details">
				</select>
			</td>
		</tr>
		<tr>
			<td align="left">
				SiteObjectBL:
			</td>
			<td align="left">
				<input type="text" maxlength="30" size="40" id="txt_siteobjectbl" name="txt_siteobjectbl" readonly>
			</td>
		</tr>
		<tr>
			<td align="left">
				Description:
			</td>
			<td align="left">
				<input type="text" maxlength="30" size="40" id="txt_description" name="txt_description" readonly>
			</td>
		</tr>
		<tr>
			<td align="left">
				DistinguishedName:
			</td>
			<td align="left">
				<input type="text" maxlength="30" size="40" id="txt_dn" name="txt_dn" readonly>
			</td>
		</tr>
		<tr>
			<td align="left">
				WhenCreated:
			</td>
			<td align="left">
				<input type="text" maxlength="30" size="40" id="txt_whencreated" name="txt_whencreated" readonly>
			</td>
		</tr>
		<tr>
			<td align="left">
				WhenChanged:
			</td>
			<td align="left">
				<input type="text" maxlength="30" size="40" id="txt_whenchanged" name="txt_whenchanged" readonly>
			</td>
		</tr>
	</table>
</body>

Open in new window

0
 
LVL 17

Author Comment

by:Premkumar Yogeswaran
ID: 37724020
Hi Rob,

Unable to input the site information.
Screenshot attached-a
HTA-Error.jpg
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 37727002
Oh sorry.  Just change this line:
            strBase = "<LDAP://" & strDNSDomain & ">"

to this
            strBase = "<LDAP://CN=Sites,CN=Configuration," & strDNSDomain & ">"


Regards,

Rob.
0
URL rewriting in AWS CloudFront

A quick how-to guide to implement with a Lambda function!

 
LVL 17

Author Comment

by:Premkumar Yogeswaran
ID: 37734291
RobSampson....!!!

                           You are Great....!!!

Thanks a TON..

Cheers,
Prem
0
 
LVL 17

Author Closing Comment

by:Premkumar Yogeswaran
ID: 37734292
Rob,

Additionally, instead of drop down box for site in the script..

Please could you help me to enter the site name manually to trigger the output in the script...??

Thanks,
Prem
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 37735730
Yep, this should work.

Regards,

Rob.

<head>
<title>Active Directory Site Information</title>
<HTA:APPLICATION 
     APPLICATIONNAME="Active Directory Site Information"
     BORDER="thin"
     SCROLL="no"
     SINGLEINSTANCE="yes"
     WINDOWSTATE="normal"
>
</head>

<script language="VBScript">

Sub Window_onLoad
	intWidth = 800
	intHeight = 600
	Me.ResizeTo intWidth, intHeight
    Me.MoveTo ((Screen.Width / 2) - (intWidth / 2)),((Screen.Height / 2) - (intHeight / 2))
    txt_SiteName.focus
End Sub

Sub Default_Buttons
	If Window.Event.KeyCode = 13 Then
		btn_getdetails.Click
	End If
End Sub

Sub Get_Details
	If Trim(txt_sitename.Value) = "" Then
		MsgBox "Please enter a site name."
		txt_sitename.focus
	Else
		txt_siteobjectbl.Value = ""
		txt_description.Value = ""
		txt_dn.Value = ""
		txt_whencreated.Value = ""
		txt_whenchanged.Value = ""

		 ' Search entire Active Directory domain.
		Set adoCommand = CreateObject("ADODB.Command")
		Set adoConnection = CreateObject("ADODB.Connection")
		adoConnection.Provider = "ADsDSOObject"
		adoConnection.Open "Active Directory Provider"
		adoCommand.ActiveConnection = adoConnection
	
		Set objRootDSE = GetObject("LDAP://RootDSE")
		
		strDNSDomain = objRootDSE.Get("defaultNamingContext")
		strBase = "<LDAP://CN=Sites,CN=Configuration," & strDNSDomain & ">"
		
		strFilter = "(&(objectcategory=site)(name=" & txt_SiteName.Value & "))"
		
		' Comma delimited list of attribute values to retrieve.
		strAttributes = "name,distinguishedName,siteobjectBL,description,whenCreated,whenChanged"
		
		' Construct the LDAP syntax query.
		strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
		adoCommand.CommandText = strQuery
	
		adoCommand.Properties("Page Size") = 100
		adoCommand.Properties("Timeout") = 30
		adoCommand.Properties("Cache Results") = False
		
		' Run the query.
		Set adoRecordset = adoCommand.Execute
		 
		' Enumerate the resulting recordset.
		blnFound = False
		Do Until adoRecordset.EOF
			blnFound = True
			On Error Resume Next
		    ' Retrieve values and display.
			txt_siteobjectbl.Value = adoRecordset("siteobjectBL").Value
			txt_description.Value = adoRecordset("description").Value
			txt_dn.Value = adoRecordset("distinguishedName").Value
			txt_whencreated.Value = adoRecordset("whenCreated").Value
			txt_whenchanged.Value = adoRecordset("whenChanged").Value
			Err.Clear
			On Error GoTo 0
		    ' Move to the next record in the recordset.
		    adoRecordset.MoveNext
		Loop
		
		' Clean up.
		adoRecordset.Close
		Set adoRecordset = Nothing
		
		adoConnection.Close
		
		If blnFound = False Then MsgBox "Unable to find site specified."
	End If
End Sub

</script>

<body STYLE="background-color:#B0C4DE; font-family: arial" onkeypress='vbs:Default_Buttons'>
	<table width='90%' height = '90%' align='center' border='0'>
		<tr>
			<td colspan="4" align="center">
				<h2>
					Active Directory Site Information
				</h2>
			</td>
		</tr>
		<tr>
			<td align='center' colspan="2">
				Enter a Site Name:
				<input type="text" maxlength="30" size="40" id="txt_sitename" name="txt_sitename">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" name="btn_getdetails" id="btn_getdetails" onclick="Get_Details" value="Get Details">
			</td>
		</tr>
		<tr>
			<td align="left">
				SiteObjectBL:
			</td>
			<td align="left">
				<input type="text" maxlength="30" size="40" id="txt_siteobjectbl" name="txt_siteobjectbl" readonly>
			</td>
		</tr>
		<tr>
			<td align="left">
				Description:
			</td>
			<td align="left">
				<input type="text" maxlength="30" size="40" id="txt_description" name="txt_description" readonly>
			</td>
		</tr>
		<tr>
			<td align="left">
				DistinguishedName:
			</td>
			<td align="left">
				<input type="text" maxlength="30" size="40" id="txt_dn" name="txt_dn" readonly>
			</td>
		</tr>
		<tr>
			<td align="left">
				WhenCreated:
			</td>
			<td align="left">
				<input type="text" maxlength="30" size="40" id="txt_whencreated" name="txt_whencreated" readonly>
			</td>
		</tr>
		<tr>
			<td align="left">
				WhenChanged:
			</td>
			<td align="left">
				<input type="text" maxlength="30" size="40" id="txt_whenchanged" name="txt_whenchanged" readonly>
			</td>
		</tr>
	</table>
</body>

Open in new window

0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question