Re: Need WMI script



Hi Mueller,

Thanks for your reply.
I have question. Is there any method which will print the out put(other than
into file) other than Wscript.Echo ..like write, print etc., My requirement
is to display the status of the group and down to the user details to the
admin and write those details to file. using filesystem we can write into
file.But how to display the details?

Regards,
Sri

"Richard Mueller [MVP]" wrote:

Sri wrote:

Due to unavailbility of .net framework in our production servers(no
permission to install the .net framework). i am planning to convert my
.net
code to vbscript.
Any one can give the equilent vbscript of the following .net code.

DirectoryEntry groupEntry = new DirectoryEntry("LDAP://"; + strDomainName);
System.DirectoryServices.DirectorySearcher tsds =
new System.DirectoryServices.DirectorySearcher(groupEntry);
tsds.Filter =
"(&(|(objectClass=user)(objectclass=group))(samAccountName=" +
strGroupName))";
tsds.SearchScope = SearchScope.Subtree;
SearchResult src1;
src1 = tsds.FindOne();


ADO can be used to search AD in VBScript. See this link:

http://www.rlmueller.net/ADOSearchTips.htm

Note that sAMAccountName must be unique in the domain. If a value is used by
a user, it cannot be used by a group. You can use the filter:

"(sAMAccountName=" & strGroupName &")"

For example:
================
Option Explicit

Dim adoCommand, adoConnection, strBase, strFilter, strAttributes

Dim strQuery, adoRecordset, strDN, strGroupName



' Setup ADO objects.

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



' Search entire Active Directory domain.
strBase = "<LDAP://dc=MyDomain,dc=com>"



' Specify sAMAccountName.

strGroupName = "TestGroup"


' Filter on objects with given name.
strFilter = "(sAMAccountName=" & strGroupName & ")"



' Comma delimited list of attribute values to retrieve.
strAttributes = "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.
strDN = adoRecordset.Fields("distinguishdName").Value

Wscript.Echo strDN

' Move to the next record in the recordset.
adoRecordset.MoveNext
Loop



' Clean up.

adoRecordset.Close

adoConnection.Close


--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab - http://www.rlmueller.net
--



.



Relevant Pages

  • Re: Need WMI script
    ... Any one can give the equilent vbscript of the following .net code. ... Dim adoCommand, adoConnection, strBase, strFilter, strAttributes ... Dim strQuery, adoRecordset, strDN, strGroupName ... ' Move to the next record in the recordset. ...
    (microsoft.public.windows.server.scripting)
  • Re: ADSI Script to return all Active Directory users with Dialin-E
    ... Dim adoCommand, adoConnection, strBase, strFilter, strAttributes ... Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strDN ... ' Move to the next record in the recordset. ... The script should be run at a command prompt with the cscript host. ...
    (microsoft.public.scripting.vbscript)
  • Re: ADO Connection, Error: (438) Object doesnt support this prope
    ... the first time i have used ADO and this is what i came up with... ... adoCommand1.ActiveConnection = adoConnection ... the beginning of the recordset after retrieving the RecordCount property. ... Set Grp = GetObject.Value) ...
    (microsoft.public.scripting.wsh)
  • Re: ADO Connection, Error: (438) Object doesnt support this prope
    ... adoCommand1.ActiveConnection = adoConnection ... the beginning of the recordset after retrieving the RecordCount property. ... Set Grp = GetObject.Value) ...
    (microsoft.public.scripting.wsh)
  • Re: get records in table that fall within current month
    ... GetDate retrieves the current date. ... Dim adoConnection As ADODB.Connection ... Dim adoRecordset As ADODB.Recordset ... The recordset will loop once for each row that meets the WHERE clause ...
    (microsoft.public.vb.general.discussion)