Solved

VBSCRIPT - Check who is member of local Admin group on a list of windows servers

Posted on 2009-05-13
10
3,574 Views
Last Modified: 2013-12-03
I have a VBSCript that lists the members of the local admin group. I would like to update this script so it uses a predefined list of servers in Servers.txt and is able to run on the remotly listed servers.
'--------------------------------------------------------------------
' AdminGroupMembers.vbs              			
'--------------------------------------------------------------------
' Description:
'--------------------------------------------------------------------
' This script will list the members of the local administrators group 
' and send the output to a file in the temp folder.
'--------------------------------------------------------------------
' Updates:
'--------------------------------------------------------------------
' 9/25/07	ARocca	v2	Delete log file if exists. This was to 
'						correct a problem with the older Credent 
'						client.
' 1/23/08	ARocca	v3	Added functionality to only report on global
'						user accounts.
'--------------------------------------------------------------------
Option Explicit
 
'---------------------------------
'Variable Declarations
'---------------------------------
Dim sLocalGroup, sComputer, sOutputFileName, sNow, sDomain, sUserProf, sTempDir, sMode
Dim oProcEnv, oLocalGroup, oFSO, oLogFile, oLocalAdmin, oTextStream, oWShell, oUser
Dim blnVerbose, x
 
'---------------------------------
'Constants
'---------------------------------
sLocalGroup = "Administrators"
 
'---------------------------------
'Initialize Objects
'---------------------------------
Set oFSO     = CreateObject("Scripting.FileSystemObject")
Set oWShell  = CreateObject("WScript.Shell")
Set oProcEnv = oWShell.Environment("Process")
 
'---------------------------------
'Identify this computer
'---------------------------------
sComputer = oProcEnv("COMPUTERNAME")
 
'---------------------------------
'Read the Command Line Arguments
'---------------------------------
sOutputFileName = ""
sMode = ""
If WScript.Arguments.Count > 0 Then
	For x = 0 To WScript.Arguments.Count -1
		If UCase(WScript.Arguments.Item(x)) = "/SILENT" Then blnVerbose = False
		If Left(UCase(WScript.Arguments.Item(x)),5) = "/FILE" Then sOutputFileName = WScript.Arguments.Item(x+1)
		If UCase(WScript.Arguments.Item(x)) = "/GLOBALONLY" Then sMode = "GLOBALONLY"
	Next
End If
 
If sOutputFileName = "" Then
	sUserProf = oWShell.ExpandEnvironmentStrings("%UserProfile%")
 
	sTempDir = oWShell.Environment("USER")("TEMP")
	sTempDir = Replace(sTempDir, "%USERPROFILE%", sUserProf)
 
	sOutputFileName=sTempDir & "\admn_" & sComputer & ".txt"
End If
 
'---------------------------------
'Delete file if it already exists
'---------------------------------
If oFSO.FileExists(sOutputFileName) Then 
	oFSO.DeleteFile sOutputFileName 
End If
 
'---------------------------------
'Create an output file
'---------------------------------
Set oLogFile = oFSO.OpenTextFile(sOutputFileName,2,True)
 
'---------------------------------
'Get an object for the 
'administrators group
'---------------------------------
Set oLocalGroup = GetObject("WinNT://" & sComputer & "/" & sLocalGroup)
 
sNow = NowUTC()
 
'---------------------------------
'Cycle through each member of the 
'administrators group
'---------------------------------
For Each oLocalAdmin In oLocalGroup.Members
	'---------------------------------
	'Report on Global user account only?
	'---------------------------------
	If sMode = "GLOBALONLY" Then
		If InStr(oLocalAdmin.ADsPath, sComputer) = 0 Then
			'---------------------------------
			'Extract domain account from the
			'ADsPath
			'---------------------------------
			sDomain = oLocalAdmin.ADsPath
			
			'---------------------------------
			'Determine if this is a Domain User
			'---------------------------------
			Set oUser = GetObject(sDomain)
			If oUser.class = "User" Then
				sDomain = Mid(sDomain, 9)
				
				If InStr(sDomain, "/") > 1 Then
					sDomain = Left(sDomain, (InStr(sDomain, "/")-1))
				Else
					sDomain = ""
				End If		
				
				'---------------------------------
				'Write the results to a log file
				'---------------------------------
				oLogFile.WriteLine(sNow & ";" & sComputer & ";" & sDomain & "\" & oLocalAdmin.Name)
			End If
			oUser = ""
		End If
	Else
		'---------------------------------
		'Determine the members domain
		'---------------------------------
		If InStr(oLocalAdmin.ADsPath, sComputer) > 0 Then
			'---------------------------------
			'Local User
			'---------------------------------
			sDomain = sComputer
		Else
			'---------------------------------
			'Extract domain account from the
			'ADsPath
			'---------------------------------
			sDomain = oLocalAdmin.ADsPath
			sDomain = Mid(sDomain, 9)
			If InStr(sDomain, "/") > 1 Then
				sDomain = Left(sDomain, (InStr(sDomain, "/")-1))
			Else
				sDomain = ""
			End If
		End If
 
		'---------------------------------	
		'Write the results to a log file
		'---------------------------------
		oLogFile.WriteLine(sNow & ";" & sComputer & ";" & sDomain & "\" & oLocalAdmin.Name)
	End If
Next
 
WScript.Quit(0)
 
'--------------------------------------------------------------------
'			   			F U N C T I O N S
'--------------------------------------------------------------------
Function DateYYYYMMDD(dt)
	'---------------------------------
	'Return a date in YYYYMMDD HHMMSS 
	'format
	'---------------------------------
 
	Dim  intHour, sAMPM
 
	intHour = Hour(dt)
	If intHour > 12 then
		intHour = intHour - 12
		sAMPM = "PM"
	Else
		sAMPM = "AM"
	End if
 
	If intHour = 12 Then sAMPM = "PM"
	If intHour = 0 Then intHour = 12
 
	DateYYYYMMDD = Year(dt) & "/" & Right(month(dt)+100, 2) & "/" & Right(day(dt)+100, 2) & " " & Right(intHour+100,2) & ":" & Right(Minute(dt) + 100, 2) & ":" & Right(second(dt) + 100, 2) & " " & sAMPM
 
End Function
'--------------------------------------------------------------------
Function NowUTC()
	'---------------------------------
	' Return the current UTC time as 
	'a string
	'---------------------------------
	Dim dtRightNow, intBias, oShell, intBiasKey, dtLocal, dtUTC
	
	'--------------------------------
	'Calculate Hours from GMT
	'--------------------------------
	Set oShell = CreateObject("Wscript.Shell") 
	
	intBiasKey = oShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\Bias") 
	If UCase(TypeName(intBiasKey)) = "LONG" Then 
		intBias = Round(intBiasKey/60) 
	End If 
	
	If UCase(TypeName(intBiasKey)) = "VARIANT()" Then 
		intBias = 0 
		For k = 0 To UBound(intBiasKey)
			intBias = intBias + (intBiasKey(k) * 256^k) 
		Next 
		intBias = Round(intBiasKey/60) 
	End If
	
	'--------------------------------
	'Get the current Time
	'--------------------------------
	dtLocal = Now()
	
	'--------------------------------
	'Get the UTC Time
	'--------------------------------
	dtUTC = dateAdd("h", intBias, dtLocal)
	
	NowUTC = DateYYYYMMDD(dtUTC)
End Function
'--------------------------------------------------------------------

Open in new window

0
Comment
Question by:Frencheee
  • 6
  • 4
10 Comments
 
LVL 38

Assisted Solution

by:Shift-3
Shift-3 earned 100 total points
ID: 24377416
You can loop through a list of computers using the example below.  Put the section of your script which is to be repeated for each computer in place of the 'Your code here comment.


Const ForReading = 1
Const TriStateUseDefault = -2
 
strList = "Servers.txt"
 
Set objList = oFSO.OpenTextFile(strList, ForReading, False, TriStateUseDefault)
arrComputers = Split(objList.ReadAll, vbCrLf)
objList.Close
 
For Each sComputer in arrComputers
    'Your code here
Next

Open in new window

0
 

Author Comment

by:Frencheee
ID: 24382943
Ive added your code, but I now get a syntax error on line 169. Have I put your code in the correct place?


'--------------------------------------------------------------------
' AdminGroupMembers.vbs              		
'--------------------------------------------------------------------
' Description:
'--------------------------------------------------------------------
' This script will list the members of the local administrators group 
' and send the output to a file in the temp folder.
'--------------------------------------------------------------------
' Updates:
'--------------------------------------------------------------------
' 9/25/07	ARocca	v2	Delete log file if exists. This was to 
'						correct a problem with the older Credent 
'						client.
' 1/23/08	ARocca	v3	Added functionality to only report on global
'						user accounts.
'--------------------------------------------------------------------
 
'--------------------------------------------------------------------
'Update to use list of servers
 
Option Explicit
 
'---------------------------------
'Variable Declarations
'---------------------------------
Dim sLocalGroup, sComputer, sOutputFileName, sNow, sDomain, sUserProf, sTempDir, sMode
Dim oProcEnv, oLocalGroup, oFSO, oLogFile, oLocalAdmin, oTextStream, oWShell, oUser
Dim blnVerbose, x
 
'---------------------------------
'Constants
'---------------------------------
sLocalGroup = "Administrators"
'---------------------------------
'Initialize Objects
'---------------------------------
Set oFSO     = CreateObject("Scripting.FileSystemObject")
Set oWShell  = CreateObject("WScript.Shell")
Set oProcEnv = oWShell.Environment("Process")
 
'---------------------------------
'Identify this computer
'---------------------------------
Const ForReading = 1
Const TriStateUseDefault = -2
 
strList = "Servers.txt"
Set objList = oFSO.OpenTextFile(strList, ForReading, False, TriStateUseDefault)
arrComputers = Split(objList.ReadAll, vbCrLf)
objList.Close
 
For Each sComputer in arrComputers
 
sComputer = oProcEnv("COMPUTERNAME")
 
'---------------------------------
'Read the Command Line Arguments
'---------------------------------
sOutputFileName = ""
sMode = ""
If WScript.Arguments.Count > 0 Then
	For x = 0 To WScript.Arguments.Count -1
		If UCase(WScript.Arguments.Item(x)) = "/SILENT" Then blnVerbose = False
		If Left(UCase(WScript.Arguments.Item(x)),5) = "/FILE" Then sOutputFileName = WScript.Arguments.Item(x+1)
		If UCase(WScript.Arguments.Item(x)) = "/GLOBALONLY" Then sMode = "GLOBALONLY"
	Next
End If
 
If sOutputFileName = "" Then
	sUserProf = oWShell.ExpandEnvironmentStrings("%UserProfile%")
 
	sTempDir = oWShell.Environment("USER")("TEMP")
	sTempDir = Replace(sTempDir, "%USERPROFILE%", sUserProf)
 
	sOutputFileName=sTempDir & "\admn_" & sComputer & ".txt"
End If
 
'---------------------------------
'Delete file if it already exists
'---------------------------------
If oFSO.FileExists(sOutputFileName) Then 
	oFSO.DeleteFile sOutputFileName 
End If
 
'---------------------------------
'Create an output file
'---------------------------------
Set oLogFile = oFSO.OpenTextFile(sOutputFileName,2,True)
 
'---------------------------------
'Get an object for the 
'administrators group
'---------------------------------
Set oLocalGroup = GetObject("WinNT://" & sComputer & "/" & sLocalGroup)
 
sNow = NowUTC()
 
'---------------------------------
'Cycle through each member of the 
'administrators group
'---------------------------------
For Each oLocalAdmin In oLocalGroup.Members
	'---------------------------------
	'Report on Global user account only?
	'---------------------------------
	If sMode = "GLOBALONLY" Then
		If InStr(oLocalAdmin.ADsPath, sComputer) = 0 Then
			'---------------------------------
			'Extract domain account from the
			'ADsPath
			'---------------------------------
			sDomain = oLocalAdmin.ADsPath
			
			'---------------------------------
			'Determine if this is a Domain User
			'---------------------------------
			Set oUser = GetObject(sDomain)
			If oUser.class = "User" Then
				sDomain = Mid(sDomain, 9)
				
				If InStr(sDomain, "/") > 1 Then
					sDomain = Left(sDomain, (InStr(sDomain, "/")-1))
				Else
					sDomain = ""
				End If		
				
				'---------------------------------
				'Write the results to a log file
				'---------------------------------
				oLogFile.WriteLine(sNow & ";" & sComputer & ";" & sDomain & "\" & oLocalAdmin.Name)
			End If
			oUser = ""
		End If
	Else
		'---------------------------------
		'Determine the members domain
		'---------------------------------
		If InStr(oLocalAdmin.ADsPath, sComputer) > 0 Then
			'---------------------------------
			'Local User
			'---------------------------------
			sDomain = sComputer
		Else
			'---------------------------------
			'Extract domain account from the
			'ADsPath
			'---------------------------------
			sDomain = oLocalAdmin.ADsPath
			sDomain = Mid(sDomain, 9)
			If InStr(sDomain, "/") > 1 Then
				sDomain = Left(sDomain, (InStr(sDomain, "/")-1))
			Else
				sDomain = ""
			End If
		End If
 
		'---------------------------------	
		'Write the results to a log file
		'---------------------------------
		oLogFile.WriteLine(sNow & ";" & sComputer & ";" & sDomain & "\" & oLocalAdmin.Name)
	End If
Next
 
WScript.Quit(0)
 
'--------------------------------------------------------------------
'			   			F U N C T I O N S
'--------------------------------------------------------------------
Function DateYYYYMMDD(dt)
	'---------------------------------
	'Return a date in YYYYMMDD HHMMSS 
	'format
	'---------------------------------
 
	Dim  intHour, sAMPM
 
	intHour = Hour(dt)
	If intHour > 12 then
		intHour = intHour - 12
		sAMPM = "PM"
	Else
		sAMPM = "AM"
	End if
 
	If intHour = 12 Then sAMPM = "PM"
	If intHour = 0 Then intHour = 12
 
	DateYYYYMMDD = Year(dt) & "/" & Right(month(dt)+100, 2) & "/" & Right(day(dt)+100, 2) & " " & Right(intHour+100,2) & ":" & Right(Minute(dt) + 100, 2) & ":" & Right(second(dt) + 100, 2) & " " & sAMPM
 
End Function
'--------------------------------------------------------------------
Function NowUTC()
	'---------------------------------
	' Return the current UTC time as 
	'a string
	'---------------------------------
	Dim dtRightNow, intBias, oShell, intBiasKey, dtLocal, dtUTC
	
	'--------------------------------
	'Calculate Hours from GMT
	'--------------------------------
	Set oShell = CreateObject("Wscript.Shell") 
	
	intBiasKey = oShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\Bias") 
	If UCase(TypeName(intBiasKey)) = "LONG" Then 
		intBias = Round(intBiasKey/60) 
	End If 
	
	If UCase(TypeName(intBiasKey)) = "VARIANT()" Then 
		intBias = 0 
		For k = 0 To UBound(intBiasKey)
			intBias = intBias + (intBiasKey(k) * 256^k) 
		Next 
		intBias = Round(intBiasKey/60) 
	End If
	
	'--------------------------------
	'Get the current Time
	'--------------------------------
	dtLocal = Now()
	
	'--------------------------------
	'Get the UTC Time
	'--------------------------------
	dtUTC = dateAdd("h", intBias, dtLocal)
	
	NowUTC = DateYYYYMMDD(dtUTC)
End Function
'--------------------------------------------------------------------
 
Next

Open in new window

0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24384262
The Next which is on line 231 should be moved up to line 163.  The functions shouldn't be inside the loop.
0
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

Author Comment

by:Frencheee
ID: 24384703
Ok its now almost there. I now get Runtime error Line 82, 2: Permission Denied

0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24387515
The file is probably read-only.  To force deletion of read-only files, append the DeleteFile method's True parameter as below.

If that doesn't work then check NTFS permissions on the file.


oFSO.DeleteFile sOutputFileName, True

Open in new window

0
 

Author Comment

by:Frencheee
ID: 24410192
Where is it trying to create the file? On the \\servername\Temp\ or on my local C: drive ?
Ive checked the server I am trying to run this against and no file exists on the C:\temp even though I have access to the server as Admin.

H:\scripts\localadmin.vbs(82, 2) Microsoft VBScript runtime error: Permission de
nied
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24411895
1. You shouldn't need lines 78-83 in the first place, since the True on line 88 will cause the file to be overwritten if it already exists.

2. The If and End If on lines 69 and 76 should be removed, since it looks like you want a new file to be generated for each computername.

3. Put in a WScript.Echo sOutputFileName after line 75 to verify the file location.
0
 

Author Comment

by:Frencheee
ID: 24451992
Ok its still not working, Ive updated the code as you said but it reports the error: Line 69 - Expected end of line statement.

Can you see if you can get this code working on your servers, then email me the code?

Thanks

Tony

'Update to use list of servers
 
Option Explicit
 
'---------------------------------
'Variable Declarations
'---------------------------------
Dim arrComputers, objList, strList, sLocalGroup, sComputer, sOutputFileName, sNow, sDomain, sUserProf, sTempDir, sMode
Dim oProcEnv, oLocalGroup, oFSO, oLogFile, oLocalAdmin, oTextStream, oWShell, oUser
Dim blnVerbose, x
 
'---------------------------------
'Constants
'---------------------------------
sLocalGroup = "Administrators"
'---------------------------------
'Initialize Objects
'---------------------------------
Set oFSO     = CreateObject("Scripting.FileSystemObject")
Set oWShell  = CreateObject("WScript.Shell")
Set oProcEnv = oWShell.Environment("Process")
 
'---------------------------------
'Identify this computer
'---------------------------------
Const ForReading = 1
Const TriStateUseDefault = -2
 
strList = "Servers.txt"
Set objList = oFSO.OpenTextFile(strList, ForReading, False, TriStateUseDefault)
arrComputers = Split(objList.ReadAll, vbCrLf)
objList.Close
 
For Each sComputer in arrComputers
 
sComputer = oProcEnv("COMPUTERNAME")
 
'---------------------------------
'Read the Command Line Arguments
'---------------------------------
sOutputFileName = ""
sMode = ""
If WScript.Arguments.Count > 0 Then
	For x = 0 To WScript.Arguments.Count -1
		If UCase(WScript.Arguments.Item(x)) = "/SILENT" Then blnVerbose = False
		If Left(UCase(WScript.Arguments.Item(x)),5) = "/FILE" Then sOutputFileName = WScript.Arguments.Item(x+1)
		If UCase(WScript.Arguments.Item(x)) = "/GLOBALONLY" Then sMode = "GLOBALONLY"
	Next
End If
 
	sOutputFileName = "" Then
	sUserProf = oWShell.ExpandEnvironmentStrings("%UserProfile%")
 
	sTempDir = oWShell.Environment("USER")("TEMP")
	sTempDir = Replace(sTempDir, "%USERPROFILE%", sUserProf)
 
	sOutputFileName=sTempDir & "\admn_" & sComputer & ".txt"
WScript.Echo sOutputFileName 	
 
 
 
'---------------------------------
'Create an output file
'---------------------------------
Set oLogFile = oFSO.OpenTextFile(sOutputFileName,2,True)
 
'---------------------------------
'Get an object for the 
'administrators group
'---------------------------------
Set oLocalGroup = GetObject("WinNT://" & sComputer & "/" & sLocalGroup)
 
sNow = NowUTC()
 
'---------------------------------
'Cycle through each member of the 
'administrators group
'---------------------------------
For Each oLocalAdmin In oLocalGroup.Members
	'---------------------------------
	'Report on Global user account only?
	'---------------------------------
	If sMode = "GLOBALONLY" Then
		If InStr(oLocalAdmin.ADsPath, sComputer) = 0 Then
			'---------------------------------
			'Extract domain account from the
			'ADsPath
			'---------------------------------
			sDomain = oLocalAdmin.ADsPath
			
			'---------------------------------
			'Determine if this is a Domain User
			'---------------------------------
			Set oUser = GetObject(sDomain)
			If oUser.class = "User" Then
				sDomain = Mid(sDomain, 9)
				
				If InStr(sDomain, "/") > 1 Then
					sDomain = Left(sDomain, (InStr(sDomain, "/")-1))
				Else
					sDomain = ""
				End If		
				
				'---------------------------------
				'Write the results to a log file
				'---------------------------------
				oLogFile.WriteLine(sNow & ";" & sComputer & ";" & sDomain & "\" & oLocalAdmin.Name)
			End If
			oUser = ""
		End If
	Else
		'---------------------------------
		'Determine the members domain
		'---------------------------------
		If InStr(oLocalAdmin.ADsPath, sComputer) > 0 Then
			'---------------------------------
			'Local User
			'---------------------------------
			sDomain = sComputer
		Else
			'---------------------------------
			'Extract domain account from the
			'ADsPath
			'---------------------------------
			sDomain = oLocalAdmin.ADsPath
			sDomain = Mid(sDomain, 9)
			If InStr(sDomain, "/") > 1 Then
				sDomain = Left(sDomain, (InStr(sDomain, "/")-1))
			Else
				sDomain = ""
			End If
		End If
 
		'---------------------------------	
		'Write the results to a log file
		'---------------------------------
		oLogFile.WriteLine(sNow & ";" & sComputer & ";" & sDomain & "\" & oLocalAdmin.Name)
	End If
Next
 
NEXT
WScript.Quit(0)
 
'--------------------------------------------------------------------
'			   			F U N C T I O N S
'--------------------------------------------------------------------
Function DateYYYYMMDD(dt)
	'---------------------------------
	'Return a date in YYYYMMDD HHMMSS 
	'format
	'---------------------------------
 
	Dim  intHour, sAMPM
 
	intHour = Hour(dt)
	If intHour > 12 then
		intHour = intHour - 12
		sAMPM = "PM"
	Else
		sAMPM = "AM"
	End if
 
	If intHour = 12 Then sAMPM = "PM"
	If intHour = 0 Then intHour = 12
 
	DateYYYYMMDD = Year(dt) & "/" & Right(month(dt)+100, 2) & "/" & Right(day(dt)+100, 2) & " " & Right(intHour+100,2) & ":" & Right(Minute(dt) + 100, 2) & ":" & Right(second(dt) + 100, 2) & " " & sAMPM
 
End Function
'--------------------------------------------------------------------
Function NowUTC()
	'---------------------------------
	' Return the current UTC time as 
	'a string
	'---------------------------------
	Dim dtRightNow, intBias, oShell, intBiasKey, dtLocal, dtUTC
	
	'--------------------------------
	'Calculate Hours from GMT
	'--------------------------------
	Set oShell = CreateObject("Wscript.Shell") 
	
	intBiasKey = oShell.RegRead("HKLM\System\CurrentControlSet\Control\TimeZoneInformation\Bias") 
	If UCase(TypeName(intBiasKey)) = "LONG" Then 
		intBias = Round(intBiasKey/60) 
	End If 
	
	If UCase(TypeName(intBiasKey)) = "VARIANT()" Then 
		intBias = 0 
		For k = 0 To UBound(intBiasKey)
			intBias = intBias + (intBiasKey(k) * 256^k) 
		Next 
		intBias = Round(intBiasKey/60) 
	End If
	
	'--------------------------------
	'Get the current Time
	'--------------------------------
	dtLocal = Now()
	
	'--------------------------------
	'Get the UTC Time
	'--------------------------------
	dtUTC = dateAdd("h", intBias, dtLocal)
	
	NowUTC = DateYYYYMMDD(dtUTC)
End Function
'--------------------------------------------------------------------

Open in new window

0
 

Accepted Solution

by:
Frencheee earned 0 total points
ID: 24466200
Ok change of plan... Ive found some code that works. It just needs tweaking.
Ive got a few servers in the OU that have been decommissioned and I will remove from the OU
In the mean time could you help me update the code to move to the next server rather than erroring when server is not found.

listlocaladmin.vbs(20, 1) (null): The network path was not found.

Const ADS_SCOPE_ONELEVEL = 1 
 
Set oConn = CreateObject("ADODB.Connection") 
Set oCommand = CreateObject("ADODB.Command") 
oConn.Provider = "ADsDSOObject" 
oConn.Open "Active Directory Provider" 
Set oCommand.ActiveConnection = oConn 
 
oCommand.Properties("Page Size") = 1000 
oCommand.Properties("Searchscope") = ADS_SCOPE_ONELEVEL 
 
sOU = "'LDAP://ou=Servers,dc=test,dc=example,dc=com'" 
 
oCommand.CommandText = "SELECT Name, ADsPath FROM " & sOU & _ 
" WHERE objectCategory ='computer'" 
Set oRecordSet = oCommand.Execute 
oRecordSet.MoveFirst 
Do Until oRecordSet.EOF 
WScript.Echo "List of member of local Administrators group for " & oRecordSet.Fields("Name").Value 
Set oLocalAdmins = GetObject("WinNT://" & oRecordSet.Fields("Name").Value & "/Administrators") 
For Each oLocalAdmin in oLocalAdmins.Members 
WScript.Echo oLocalAdmin.Name 
Next 
oRecordSet.MoveNext 
Loop 

Open in new window

0
 

Author Comment

by:Frencheee
ID: 24466580
On Error Resume Next
Fixed it myself. But will award some points to shift 3
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question