I got a script online that was taken from the book 'Managing Windows with VBScript and WMI' - it is basically used for gathering information about all the computers on your domain.
link
So I wanted to modify it slightly so that I could enter a search string to get only computers named a certain way (example, if all the Customer Service PCs were named DNCS0##). Here's a chunk of the code that ws in the orginal script, plus the test I added for the search pattern in bold (which is supplied by the user earlier in the script) and the function it calls.
So without my additions (in bold), the script seems to work fine - it took all day to run yesterday because the directory is a mess and there are old computer accounts in there that need to be removed, but it worked.
With my additions, it still works... kind of. It does find PCs with the search string in them, but not all of them. Additionally, it produces duplicate results... I'll get 3 unique systems, then 6 lines describing the same system, then it will have another unique one, then maybe 2 lines describing another, etc... it seems random but I'm sure I'm just doing something stupid.
I'm new to VBScript (just started messing with it about a week ago) and programming/coding/scripting in general, so it's probably some small mistake. Any ideas? I can post the entire script if it helps...
link
So I wanted to modify it slightly so that I could enter a search string to get only computers named a certain way (example, if all the Customer Service PCs were named DNCS0##). Here's a chunk of the code that ws in the orginal script, plus the test I added for the search pattern in bold (which is supplied by the user earlier in the script) and the function it calls.
Dim oObject, sComputerName, sDetails
For Each oObject In oDomain
If oObject.Class = "Computer" and _
MyRegEx(sPattern).Test(oObject.Name) Then
sComputerName = oObject.Name
sDetails = GetOSInfo(sComputerName) 'Calls Function that gathers computer info
oOutput.Write sDetails
End If
Next
---------------
Function MyRegEx(Pattern)
Set MyRegEx = New RegExp
MyRegEx.Pattern = Pattern
MyRegEx.IgnoreCase = True
MyRegEx.Global = True
End Function
So without my additions (in bold), the script seems to work fine - it took all day to run yesterday because the directory is a mess and there are old computer accounts in there that need to be removed, but it worked.
With my additions, it still works... kind of. It does find PCs with the search string in them, but not all of them. Additionally, it produces duplicate results... I'll get 3 unique systems, then 6 lines describing the same system, then it will have another unique one, then maybe 2 lines describing another, etc... it seems random but I'm sure I'm just doing something stupid.
I'm new to VBScript (just started messing with it about a week ago) and programming/coding/scripting in general, so it's probably some small mistake. Any ideas? I can post the entire script if it helps...