• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VBScript help

Booty

Senior member
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.

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...

 
Back
Top