In-domain computer and user acquisition implementation VBS code _VBS

Source: Internet
Author: User
Tags ldap
displays all computer names and numbers in the current domain

Copy Code code as follows:

Const Ads_scope_subtree = 2
Set objRootDSE = GetObject ("LDAP://rootDSE")
Strdomain = Objrootdse.get ("defaultNamingContext")
Set objconnection = CreateObject ("ADODB. Connection ")
Set objcommand = CreateObject ("Adodb.command")
Objconnection.provider = "Adsdsoobject"
Objconnection.open "Active Directory Provider"
Set objcommand.activeconnection = objconnection
objCommand.Properties ("Page Size") = 1000
objCommand.Properties ("searchscope") = Ads_scope_subtree
Objcommand.commandtext = "SELECT * from ' ldap://" & Strdomain & "' WHERE objectcategory= ' computer '"
Set objRecordSet = Objcommand.execute
Objrecordset.movefirst
Do Until objrecordset.eof
WScript.Echo Objrecordset.fields ("ADsPath"). Value
Objrecordset.movenext
Loop
WScript.Echo ""
WScript.Echo "Total Computer:" &objrecordset.recordcount

Displays the name and number of all users in the current domain
Copy Code code as follows:

Const ads_scope_subtree = 2
Set objRootDSE = GetObject ("LDAP://rootDSE")
Strdomain = Objrootdse.get ("defaultNamingContext")
Set objconnection = CreateObject ("ADODB. Connection ")
Set objcommand = CreateObject (" ADODB. Command ")
Objconnection.provider =" Adsdsoobject "
Objconnection.open" Active Directory Provider "
Set obj Command.activeconnection = objconnection
objCommand.Properties ("Page Size") = 1000
objCommand.Properties ("Sea Rchscope ") = ads_scope_subtree
Objcommand.commandtext =" select * from ' ldap://"& Strdomain &" ' WHERE obje ctcategory= ' user '
Set objrecordset = Objcommand.execute
Objrecordset.movefirst
do Until Objrecordset.eo F
WScript.Echo Objrecordset.fields ("ADsPath"). Value
Objrecordset.movenext
Loop
WScript.Echo "
WScript.Echo" Total User: "&objrecordset.reco Rdcount
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.