Re: Need WMI script
- From: Sriman <Sriman@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 11 Apr 2007 06:34:01 -0700
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
--
- Follow-Ups:
- Re: Need WMI script
- From: Richard Mueller [MVP]
- Re: Need WMI script
- References:
- Re: Need WMI script
- From: Richard Mueller [MVP]
- Re: Need WMI script
- Prev by Date: Re: Event log check
- Next by Date: Re: Need WMI script
- Previous by thread: Re: Need WMI script
- Next by thread: Re: Need WMI script
- Index(es):
Relevant Pages
|