I have came across this script, and I LOVE the way it pulls in the machine info and outputs it to Excel. The format is great and the fact that it can be used to be pushed out via GPO and left on a network drive to update the Excel is awesome. My only issue is that I need it modified to pull in the monitor Serial Numbers and Models on up to 3 monitors per machine. If two is all that can be done that is fine. I have already modified the header to show what I would like for it to pull in. It also shows the format that I would like it to be in. Can someone fix it so that It will get the monitor info, or walk me threw on how to get it to work the way I want. I have already been to http://www.microsoft.com/technet/scriptcenter/resources/begin/archive.mspx and now I feel more lost than I was before. Any help would be great.
Option Explicit
Call VendorInfo
Sub VendorInfo
‘ Created by Krystian Karia
‘ Dated 16/12/2008
‘ Script that can be used in a GPO to
‘ Get Info about the computer it is
‘ running on and put it into a CSV file
‘ on a network share. It checks if any
‘ duplicates are found and if not, will
‘ create the file if not alrady there
‘ and write to it, or it will just
‘ append to the file if its already been
‘ created.
Dim fso, objWMIService, objItem, oFile, oDuplicateCheck
Dim sFileLocation, strHeader, strComputer, strIDNumber
Dim strOutput, strResults, strDuplicateLine
Dim colItems
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
‘ Initialize the variables
sFileLocation = “c:\KKVendor.csv” ‘ Put your filename and network share here i.e. \\server\share\filename.csv
strHeader = “UserName,ComputerName,Domain,IP Address,ID No.,Name,Vendor,Date,Monitor Serial 1,Monitor Serial 2, Monitor Serial 3, Monitor Model 1, Monitor Model 2, Monitor Model 3” & vbNewLine
strComputer = “.”
‘ Create the objects
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
‘ Get Username & Computer & Domain
Set colItems = objWMIService.ExecQuery(“SELECT * FROM Win32_ComputerSystem”, “WQL”, _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
strOutput = strOutput & objItem.UserName & “,”
strOutput = strOutput & objItem.Name & “,”
strOutput = strOutput & objItem.Domain & “,”
Next
‘Get IP Address
Set colItems = objWMIService.ExecQuery _
(“Select IPAddress From Win32_NetworkAdapterConfiguration Where IPEnabled = True”)
For Each objItem In colItems
If objItem.IPaddress(0) <> “0.0.0.0” Then
strOutput = strOutput & objItem.IPAddress(0) & “,”
Exit For ‘ We only want the first one it comes across
End If
Next
‘ Get ID No. Name, Vendor and Version
Set colItems = objWMIService.ExecQuery(“SELECT * FROM Win32_ComputerSystemProduct”, “WQL”, _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
strIDNumber = objItem.IdentifyingNumber
strOutput = strOutput & strIDNumber & “,”
strOutput = strOutput & objItem.Name & “,”
strOutput = strOutput & objItem.Vendor & “,”
‘strOutput = strOutput & objItem.Version & “,”
strOutput = strOutput & Date() & vbNewLine
Next
‘ Write Results To File
If fso.FileExists(sFileLocation) = False Then
‘ Create and write to file with header
Set oFile = fso.OpenTextFile(sFileLocation, ForWriting, True)
If Err.Number <> 0 Then
‘ You could write to the event log here
Exit Sub
End If
strResults = oFile.Write(strHeader & strOutput)
Else
‘ Check if we already have this ID in the csv file
Set oDuplicateCheck = fso.OpenTextFile(sFileLocation, ForReading, False)
Do Until oDuplicateCheck.AtEndOfStream
strDuplicateLine = oDuplicateCheck.ReadLine
If InStr(strDuplicateLine, strIDNumber) > 0 Then
‘ Duplicate found – close file and exit sub
oDuplicateCheck.Close
Exit Sub
End If
Loop
‘ No duplicates found – close file ready for later
oDuplicateCheck.Close
‘ File exists so append to it without header
Set oFile = fso.OpenTextFile(sFileLocation, ForAppending, False)
If Err.Number <> 0 Then
‘ You could write to the event log here
Exit Sub
End If
strResults = oFile.Write(strOutput)
End If
End Sub