Re: Help modifying this script

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



You can use ADO to retrieve the NetBIOS names of all computers in your
domain. See this link for more:

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

The value of the sAMAccountName attribute is the NetBIOS name of the
computer with a trailing "$" appended. Retrieve sAMAccountName and strip of
the last character. A brief example of the outer loop you need would be:
================
Option Explicit

Dim objCommand, objConnection, strBase, strFilter, strAttributes

Dim strQuery, objRecordset, strNTName



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

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


' Filter on computer objects.
strFilter = "(objectCategory=computer)"

' Comma delimited list of attribute values to retrieve.
strAttributes = "sAMAccountName"

' Construct the LDAP syntax query.
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 100
objCommand.Properties("Timeout") = 30
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute


' Enumerate the recordset.
Do Until objRecordSet.EOF

' Retrieve NetBIOS name of computer.

strNTName = objRecordSet.Fields("sAMAccountName").Value

' Remove trailing "$"

strNTName = Left(strNTName, Len(strNTName) - 1)

' Retrieve information on this computer.

' ... substitute your code, or call a subroutine.



' Move to next row in the recordset.

objRecordSet.MoveNext
Loop

===========

You can place your code in the loop, or place your code in a subroutine that
is called from the loop once for each computer. For an example of a similar
program to inventory computers using WMI, see this link:



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


This program uses ADO to retrieve all computer NetBIOS names, then pings
each to see if they are online. Only if the ping gets a response does the
program connect with WMI. This saves waiting for the connection attempt to
timeout. You also want the program to continue if any computer is off line,
rather than just halting. My example documents to a spread***.

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

"meridean" <chris.john.flynn@xxxxxxxxx> wrote in message
news:1161707378.228459.319510@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi all,

Is anyone able to help me modify the attached script to search Active
Directory and return the results for all Computers?

Thanks In Advance.

##################################################################################
'#########################################
'Script to Capture all Installed Software
'and output this to a file.
'
'#########################################

'Set File Path
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.CreateTextFile(inputbox("Please enter a valid
path and filename", "input") & ".txt", True)
Const HKLM = &H80000002 'HKEY_LOCAL_MACHINE
Const adVarChar = 200' Set the data type to variant.
Const MaxCharacters = 100
Const adSingle = 4
strComputer = "."
strKey = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\"
strEntry1a = "DisplayName"
strEntry1b = "QuietDisplayName"
strEntry2 = "VersionMajor"
strEntry3 = "VersionMinor"
strEntry4 = "InstallDate"
strEntry5 = "EstimatedSize"

Set DataList = CreateObject("ADOR.Recordset")
DataList.Fields.Append "DisplayName", adVarChar, MaxCharacters
DataList.Fields.Append "Version", adVarChar, MaxCharacters
DataList.Fields.Append "InstallDate", adVarChar, MaxCharacters
DataList.Fields.Append "EstimatedSize", adVarChar, MaxCharacters
DataList.Open

Set objReg = GetObject("winmgmts://" & strComputer & _
"/root/default:StdRegProv")
objReg.EnumKey HKLM, strKey, arrSubkeys

For Each strSubkey In arrSubkeys
intRet1 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
strEntry1a, strValue1)
If intRet1 <> 0 Then
intRet2 = objReg.GetStringValue(HKLM, strKey & strSubkey, _
strEntry1b, strValue1)
If intRet2 <> 0 Then
strValue1 = strSubkey
End If
End If
objReg.GetDWORDValue HKLM, strKey & strSubkey, _
strEntry2, intValue2
objReg.GetDWORDValue HKLM, strKey & strSubkey, _
strEntry3, intValue3
If (Not IsNull(intValue2)) And (Not IsNull(intValue3)) Then
strVersion = intValue2 & "." & intValue3
Else
strVersion = ""
End If
objReg.GetStringValue HKLM, strKey & strSubkey, _
strEntry4, strValue4
If Not IsNull(strValue4) Then
strInstallDate = Mid(strValue4, 5, 2) & "/" & Right(strValue4, 2) &
_
"/" & Left(strValue4, 4)
Else
strInstallDate = ""
End If
objReg.GetDWORDValue HKLM, strKey & strSubkey, _
strEntry5, intValue5
If Not IsNull(intValue5) Then
strEstimatedSize = CStr(Round(intValue5/1024, 3))
Else
strEstimatedSize = ""
End If
DataList.AddNew
DataList("DisplayName") = strValue1
DataList("Version") = strVersion
DataList("InstallDate") = strInstallDate
DataList("EstimatedSize") = strEstimatedSize
DataList.Update
Next

DataList.Sort = "DisplayName"
DataList.MoveFirst

objTextFile.WriteLine "Computer Name" & vbTab & "Display Name" & vbTab
& "Version" & vbTab & "Install Date" & vbTab & "Estimated Size (MB)"

Do Until DataList.EOF
objTextFile.WriteLine strComputer & vbTab &
DataList.Fields.Item("DisplayName") & vbTab &
DataList.Fields.Item("Version") & vbTab &
DataList.Fields.Item("InstallDate") & vbTab &
DataList.Fields.Item("EstimatedSize")
DataList.MoveNext
Loop

DataList.Close
objTextFile.Close
WScript.Echo "This Script is Now Complete"
##################################################################################



.


Quantcast