Re: Modifiy this script to read a nested "Computers" container
From: John (no email)
Date: 04/08/04
- Next message: name: "1053 posts"
- Previous message: Al Dunbar [MS-MVP]: "Re: Help!!!"
- In reply to: Richard Mueller [MVP]: "Re: Modifiy this script to read a nested "Computers" container"
- Next in thread: John : "Re: Modifiy this script to read a nested "Computers" container"
- Reply:(deleted message) John : "Re: Modifiy this script to read a nested "Computers" container"
- Reply:(deleted message) Richard Mueller [MVP]: "Re: Modifiy this script to read a nested "Computers" container"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 08 Apr 2004 22:20:18 +0100
Hi Richard.. I ran the below script and received the following error.
There are computer accounts in both the top level OU called Site1 and
the child OU called computers. Any suggestions on the null error?
Thanks Richard for your help.
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
C:\get local admin.vbs(45, 1) (null): 0x80041010
Exit code: 0 , 0000h
Set Dom = GetObject("LDAP://ou=Computers,ou=site1,dc=xyz,dc=com")
Dom.Filter = Array("Computer")
strLogFile = "LocalAdmins.LOG"
strLocalAdminGroup = "Administrators"
Set objFSO = CreateObject("Scripting.fileSystemObject")
on error resume next
Set objLogFile = objFSO.CreateTextFile(strLogFile, NO_OVERWRITE)
If Err.Number <> 0 Then
WScript.Echo "Cannot create " & strLogFile & " -OR- " _
& strLogFile & "already exists."
WScript.Quit
End If
On Error GoTo 0
objLogFile.WriteLine("**************** Started at " & Now() _
& "****************")
objLogFile.WriteLine()
For Each Member in Dom
strComputer = Member.sAMAccountName
Call GetLocalAdmins(strComputer)
Next
objLogFile.WriteLine()
objLogFile.WriteLine("**************** Finished at " & Now() _
& "****************")
objLogFile.Close
'-=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=-
' SUB GetLocalAdmins
' purpose: Retrieve list of local administrators from online machines
' input: strComputer (a machine name)
' output: results are echoed on screen and saved in strLogFile
' notes: uses Win32_PingStatus class ("strPinger" must be XP or 2003)
'-=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=--=[]=-
Sub GetLocalAdmins(HostName)
strPinger = "."
Set objWMIService = GetObject("winmgmts:" &
"{impersonationLevel=impersonate}!\\" & strPinger & "\root\cimv2")
Set colPingedComputers = objWMIService.ExecQuery ("Select * from
Win32_PingStatus Where Address = '" & strComputer & "'")
objLogFile.WriteLine("-----------------------------------------------------")
For each objComputer in colPingedComputers
If objComputer.StatusCode = 0 Then
WScript.Echo "Processing " & strComputer
objLogFile.WriteLine(strComputer)
Set objLocalAdminGroup = GetObject("WinNT://" & strComputer & "/" &
strLocalAdminGroup)
For Each objLocalAdmin In objLocalAdminGroup.Members
objLogFile.WriteLine("Member of " & strLocalAdminGroup & " group: " &
objLocalAdmin.Name)
Next
Set objLocalAdminGroup = Nothing
Else
WScript.Echo strComputer & " Offline"
objLogFile.WriteLine(strComputer & " Offline")
End If
Next
End Sub
On Mon, 5 Apr 2004 23:47:15 -0500, "Richard Mueller [MVP]"
<rlmueller-NOSPAM@ameritech.NOSPAM.net> wrote:
>Yes, the Distinguished Name you gave should make the code search the
>"ou=site1" ou and all sub (child) containers and OU's. However, since it
>seems you only want to search one OU, you could set the base of the search
>to be "ou=Computers,ou=site1" and forget about a recursive subroutine. For
>example:
>
>Set Dom = GetObject("LDAP://ou=Computers,ou=Site1,dc=xyz,dc=com")
>Dom.Filter = Array("computer")
>
>For Each Member in Dom
> strComputer = Member.sAMAccountName
> Call GetLocalAdmins(strComputer)
>Next
>
>In other words, your original code should work if you just use LDAP,
>substitute the Distinguished Name of the ou=Computers,ou=Site1 OU, and
>substitute "Member.sAMAccountName" for "Member.Name". Also, you had
>Array("computers") where it should be Array("computer"). (I haven't checked
>Sub GetLocalAdmins.)
>
>Note, that in the Recursive sub I posted earlier, where I used
>"Member.Name", it should have been "Member.sAMAccountName". The attribute
>name is different when using the LDAP provider and I missed that
>modification. I hope this helps.
>
>--
>Richard
>Microsoft MVP Scripting and ADSI
>HilltopLab web site - http://www.rlmueller.net
- Next message: name: "1053 posts"
- Previous message: Al Dunbar [MS-MVP]: "Re: Help!!!"
- In reply to: Richard Mueller [MVP]: "Re: Modifiy this script to read a nested "Computers" container"
- Next in thread: John : "Re: Modifiy this script to read a nested "Computers" container"
- Reply:(deleted message) John : "Re: Modifiy this script to read a nested "Computers" container"
- Reply:(deleted message) Richard Mueller [MVP]: "Re: Modifiy this script to read a nested "Computers" container"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|