Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to: List members of the "Local Administrator Group 2

Status
Not open for further replies.

dabomb311

MIS
May 20, 2009
2
US
looking at this thread "thread329-901034"

can someone tell me what the container.txt file should look like..

mine looks kinda like this
"CN=COMPUTERNAME,OU=OUNAME,OU=OUNAME2,OU=OU NAME,DC=DC,DC=DC1,DC=COM"

all on 1 line. but the pingsuccessful and pingfailed .txt files are blank.
 
complete vbs script... i get no results in either the ping or no ping files
-----------------------------------------------
'========
'= Main =
'========
Dim Computer, elem
PingSystems
MakeArray
MsgBox "Listing Local Admins is now complete"

'================
'= Ping Systems =
'================
Sub PingSystems()
Dim Outputfile, FSO, OFile, Outputfile2, oFile2
Dim iFile, objContainer, StdOut, objShell

OutputFile="C:\share\ad\pingSuccessful.txt"
Set FSO = CreateObject("Scripting.FileSystemObject")
Set oFile = FSO.CreateTextFile(OutputFile, True)
OutputFile2="C:\share\ad\pingFailed.txt"
Set oFile2 = FSO.CreateTextFile(OutputFile2, True)

InputFile="c:\share\ad\container.txt" 'contains OU structure

Set iFile = FSO.OpenTextFile(InputFile, 1, true) 'assume existing else create an empty file

WScript.Echo "Pinging Systems Now..."
Do until iFile.AtEndOfStream
strComputerContainer = iFile.ReadLine

Set objContainer = GetObject("LDAP://" & strComputerContainer)
objContainer.Filter = Array("Computer")

Set StdOut = WScript.StdOut
Set objShell = CreateObject("WScript.Shell")

On Error Resume Next

For Each objComputer In objContainer
Computer = Split(objComputer.Name, "=")(1)
Set objScriptExec = objShell.Exec("ping -n 2 -w 1000 " & Computer)
do while objScriptExec.status=0
wscript.sleep 100
loop
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from")<>0 Then
oFile.WriteLine(Computer)
Else
oFile2.WriteLine(Computer)
End If
Next
Loop
iFile.close
oFile2.close
oFile.close
WScript.Echo "Pinging Systems Complete!"
End Sub


'========================
'= Opens TXT into array =
'========================
Sub MakeArray
Const ForReading = 1
Const WKS = "c:\share\ad\pingsuccessful.txt"
Dim fso, f
Dim arrText()
Dim text

Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso_OpenTextFile(WKS, ForReading)

iUpperBound = 0
While Not f.AtEndOfStream
ReDim Preserve arrText(iUpperBound)
arrText(UBound(arrText)) = f.ReadLine
iUpperBound = iUpperBound + 1
Computer = arrText(UBound(arrText))
WScript.Echo Computer
if not isempty(Computer) then
GetLocalAdmins Computer 'calls sub to get local admin info - pass computer as variable explicitly
end if
Wend
f.Close
End Sub

'=====================
'= Gets Local Admins =
'=====================
Sub GetLocalAdmins (Computer)
Dim objComp
strComputer = Computer
Set objComp = GetObject("WinNT://" & strComputer) 'seems to have issues here.
objComp.GetInfo 'or here....
If objComp.PropertyCount > 0 Then
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
If objGroup.PropertyCount > 0 Then
WScript.Echo "The members of the local Administrators group on " & strComputer & " are:"
For Each mem In objGroup.Members
WScript.echo vbTab & Right(mem.adsPath,Len(mem.adsPath) - 8)
Next
Else
WScript.echo "** Connecting to the local Administrators group on " & strComputer & " failed."
WScript.Quit 1
End If
Else
WScript.Echo "** Connecting to " & strComputer & " failed."
WScript.Quit 1
End If
End Sub
 
Give my script a try instead.

Note that this script only checks for live servers. You can remove the code that restricts to just servers. Remove the parts in [red]red[/red] to show all machines.

Code:
'==========================================================================
'
' NAME: ReportLiveServers.vbs
'
' AUTHOR: Mark D. MacLachlan , The Spider's Parlor
' URL: [URL unfurl="true"]http://www.thespidersparlor.com[/URL]
' DATE  : 5/1/2009
' COPYRIGHT © 2009, All Rights Reserved
'
' COMMENT: 
'
'    THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
'    ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED To
'    THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'    PARTICULAR PURPOSE.
'
'    IN NO EVENT SHALL THE SPIDER'S PARLOR AND/OR ITS RESPECTIVE SUPPLIERS 
'    BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
'    DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
'    WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
'    ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
'    OF THIS CODE OR INFORMATION.
'
'==========================================================================

strDn = InputBox("Enter the LDAP path of the domain or OU you wish to report servers from." & _
vbCrLf & "Example: DC=root,DC=company,DC=com","Enter LDAP")
domStr = strDN
domStr = Replace(domStr,",",".")
domStr = Replace(domStr,"DC=","")
domStr = Replace(domStr,"OU=","")
domStr = Replace(domStr,"CN=","")

Report = "Live servers found in " & domStr & vbCrLf

EnumOU(strDN)

dateStr = Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & Year(Date)
' Specify the log file. This file will be created if it does not
' exist. Otherwise, the program will append to the file.
strFilePath = "c:\LiveComputers-" & domStr & "-" & dateStr & ".txt"
' Open the log file for write access. Append to this file.
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath, 8, True, 0)
If (Err.Number <> 0) Then
    On Error GoTo 0
    Wscript.Echo "File " & strFilePath & " cannot be opened"
    Set objFSO = Nothing
    Wscript.Quit
End If
On Error GoTo 0
'write the report & close the file.
objFile.Write Report
objFile.Close

'launch the report
Set WshShell = CreateObject("Wscript.Shell")
WshShell.Run strFilePath


Function EnumOU(strDN)
	' Use ADO to search Active Directory. 
	Set objCommand = CreateObject("ADODB.Command") 
	Set objConnection = CreateObject("ADODB.Connection") 
	objConnection.Provider = "ADsDSOObject" 
	objConnection.Open "Active Directory Provider" 
	objCommand.ActiveConnection = objConnection 
	strBase = "<LDAP://" & strDN & ">" 
	' Filter on Organizational Units. 
	strFilter = "(objectCategory=Computer)" 
	strAttributes = "Name,operatingSystem" 
	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 
	  strComputer = objRecordSet.Fields("Name")
	  liveCheck = PingStatus(strComputer)
	  'WScript.Echo strComputer & " " & liveCheck[red]
	  If InStr(objRecordSet.Fields("operatingSystem"),"Server") > 0 Then[/red]
	  	If liveCheck = "Success" Then
	  		Report = Report & strComputer & vbCrLf
	  	End If
[red]	  End If[/red]
	  
	  objRecordSet.MoveNext 
	Loop 
	' Clean up. 
	objConnection.Close 
End Function

Function PingStatus(strComputer)

    On Error Resume Next
    Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colPings = objWMIService.ExecQuery _
      ("SELECT * FROM Win32_PingStatus WHERE Address = '" & strComputer & "'")
    For Each objPing in colPings
        Select Case objPing.StatusCode
            Case 0 PingStatus = "Success"
            Case 11001 PingStatus = "Status code 11001 - Buffer Too Small"
            Case 11002 PingStatus = "Status code 11002 - Destination Net Unreachable"
            Case 11003 PingStatus = "Status code 11003 - Destination Host Unreachable"
            Case 11004 PingStatus = _
              "Status code 11004 - Destination Protocol Unreachable"
            Case 11005 PingStatus = "Status code 11005 - Destination Port Unreachable"
            Case 11006 PingStatus = "Status code 11006 - No Resources"
            Case 11007 PingStatus = "Status code 11007 - Bad Option"
            Case 11008 PingStatus = "Status code 11008 - Hardware Error"
            Case 11009 PingStatus = "Status code 11009 - Packet Too Big"
            Case 11010 PingStatus = "Status code 11010 - Request Timed Out"
            Case 11011 PingStatus = "Status code 11011 - Bad Request"
            Case 11012 PingStatus = "Status code 11012 - Bad Route"
            Case 11013 PingStatus = "Status code 11013 - TimeToLive Expired Transit"
            Case 11014 PingStatus = _
              "Status code 11014 - TimeToLive Expired Reassembly"
            Case 11015 PingStatus = "Status code 11015 - Parameter Problem"
            Case 11016 PingStatus = "Status code 11016 - Source Quench"
            Case 11017 PingStatus = "Status code 11017 - Option Too Big"
            Case 11018 PingStatus = "Status code 11018 - Bad Destination"
            Case 11032 PingStatus = "Status code 11032 - Negotiating IPSEC"
            Case 11050 PingStatus = "Status code 11050 - General Failure"
            Case Else PingStatus = "Status code " & objPing.StatusCode & _
               " - Unable to determine cause of failure."
        End Select
    Next
End Function

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top