I must first preface this with the fact that I am a novice scripter.
I put together this script to go throughout our environment to find any user accounts that don't fit our predefined users in our network. The script is only for local accounts (the A.D. query was much easier). but I am hitting a snag. Here is what I have found.
The script calls a list of computers in the computers.txt file, if it hits a computer that is non-microsoft or doesn't adhere to wmi, then it repeats the command off of the last computer in the list. for instance, if I have a computer list of:
and computer 3 and 4 are not windows based, the script gives me the user accounts three times (once for computer2, and twice for each bogus name it hits) in my output. I can't seem to get rid of this duplication. any ideas?
On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\CIMV2")
Set colItems = objWMIService.ExecQuery( _
"SELECT Domain, Name FROM Win32_UserAccount WHERE LocalAccount = True",,48)
For Each objItem in colItems
if objItem.Name <> "Administrator" AND _
objItem.Name <> "Guest" AND left(objItem.Name ,4) <> "IUSR" AND left(objItem.Name ,6) <> "SUPPOR" _
AND objItem.Name <> "ASPNET" AND objItem.Name <> "testuser" AND objItem.Name <> "HelpAssistant" _
AND objItem.Name <> "SQLDebugger" AND left(objItem.Name ,4) <> "IWAM" Then
Wscript.Echo objItem.Name & "," & objItem.Domain
' & "," & objItem.FullName & "," & objItem.SID
'Wscript.Echo "Domain: " & objItem.Domain