Our users have a flag file at the root of their profiles
(C:\Docume~1\%USERNAME%), based on whether or not they received our printer
migration logon script. I'd like to scan all of these computers to see who
has the flag file, but I've never used VB to pull names of computers from AD
before.

Does anybody have a generic canned script that will pull names of computers
from AD to check for a file on each computer?


Thanks for any help or suggestions!

Re: Scan AD Computers for text file by Jerold

Jerold
Mon Apr 10 12:46:35 CDT 2006

On Mon, 10 Apr 2006 10:39:01 -0700, stev379 <stev379@discussions.microsoft.com> wrote:

>Our users have a flag file at the root of their profiles
>(C:\Docume~1\%USERNAME%), based on whether or not they received our printer
>migration logon script. I'd like to scan all of these computers to see who
>has the flag file, but I've never used VB to pull names of computers from AD
>before.
>
>Does anybody have a generic canned script that will pull names of computers
>from AD to check for a file on each computer?
>
>
>Thanks for any help or suggestions!

The following will return all the NetBIOS computer names in the domain your are logged into:

On Error Resume Next
Dim objConnection, objCommand, objRootDSE, strDNSDomain
Dim strFilter, strQuery, objRecordSet
Set objConnection = CreateObject("ADODB.Connection")
Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOOBject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"
strFilter = "(&(objectCategory=computer))"
strAttributes = "Name"
strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
objCommand.CommandText = strQuery
objCommand.Properties("Page Size") = 99999
objCommand.Properties("Timeout") = 300
objCommand.Properties("Cache Results") = False
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst
Do Until objRecordSet.EOF
strSA = objRecordSet.Fields("Name")
Wscript.Echo strSA
objRecordSet.MoveNext
Loop
objConnection.Close
Set objConnection = Nothing
Set objCommand = Nothing
Set objRootDSE = Nothing
Set objRecordSet = Nothing

Jerold Schulman
Windows Server MVP
JSI, Inc.
http://www.jsiinc.com
http://www.jsifaq.com

Re: Scan AD Computers for text file by stev379

stev379
Mon Apr 10 14:01:02 CDT 2006

COOL! Thanks Jerold!
The script you posted made the lights come on for a lot of other things as
well.



"Jerold Schulman" wrote:

> On Mon, 10 Apr 2006 10:39:01 -0700, stev379 <stev379@discussions.microsoft.com> wrote:
>
> >Our users have a flag file at the root of their profiles
> >(C:\Docume~1\%USERNAME%), based on whether or not they received our printer
> >migration logon script. I'd like to scan all of these computers to see who
> >has the flag file, but I've never used VB to pull names of computers from AD
> >before.
> >
> >Does anybody have a generic canned script that will pull names of computers
> >from AD to check for a file on each computer?
> >
> >
> >Thanks for any help or suggestions!
>
> The following will return all the NetBIOS computer names in the domain your are logged into:
>
> On Error Resume Next
> Dim objConnection, objCommand, objRootDSE, strDNSDomain
> Dim strFilter, strQuery, objRecordSet
> Set objConnection = CreateObject("ADODB.Connection")
> Set objCommand = CreateObject("ADODB.Command")
> objConnection.Provider = "ADsDSOOBject"
> objConnection.Open "Active Directory Provider"
> Set objCommand.ActiveConnection = objConnection
> Set objRootDSE = GetObject("LDAP://RootDSE")
> strDNSDomain = objRootDSE.Get("defaultNamingContext")
> strBase = "<LDAP://" & strDNSDomain & ">"
> strFilter = "(&(objectCategory=computer))"
> strAttributes = "Name"
> strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
> objCommand.CommandText = strQuery
> objCommand.Properties("Page Size") = 99999
> objCommand.Properties("Timeout") = 300
> objCommand.Properties("Cache Results") = False
> Set objRecordSet = objCommand.Execute
> objRecordSet.MoveFirst
> Do Until objRecordSet.EOF
> strSA = objRecordSet.Fields("Name")
> Wscript.Echo strSA
> objRecordSet.MoveNext
> Loop
> objConnection.Close
> Set objConnection = Nothing
> Set objCommand = Nothing
> Set objRootDSE = Nothing
> Set objRecordSet = Nothing
>
> Jerold Schulman
> Windows Server MVP
> JSI, Inc.
> http://www.jsiinc.com
> http://www.jsifaq.com
>