Dim objWMIPrinters
Dim colItems
Dim oPrinter
Dim ErrorStateToString
Dim oAPI
Dim oExec
Dim LOgEVentCOmmand
Dim oArgs
Dim SourceID
Dim ManagedEntityID
Dim TargetComputer
Dim oInst
Dim oDiscoveryData
Dim NetbiosName
DIM OSVersion
'Prevents failure on error - it is possible some discovery data will not be present for some printers
'This clause will allow skipping of those errors to add the discovery data that is present.
On Error Resume Next
Set oAPI = CreateObject("MOM.ScriptAPI")
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
Set objWMIPrinters = GetObject("winmgmts://./root/cimv2")
Set colItems = objWMIPrinters.ExecQuery("Select * from Win32_Printer")
'Set WshShell = CreateObject("Wscript.Shell")
For each oPrinter in colItems
' SET TO 1 FOR TESTING. REVERT TO 0 FOR PRODUCTION
If oPrinter.Shared = 0 Then
wscript.echo "Printer " & oPrinter.name & " is not shared. Ignored."
Else
wscript.echo "Printer " & oPrinter.name & " - " & ErrorStateToString
Select Case OSVersion
CASE "2003"
Set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Tasty.Printer.Monitoring.Windows2003.PrintServer.Printer']$")
Call oInst.AddProperty("$MPElement[Name='Tasty.Printer.Monitoring.Windows2003.PrintServer.Printer']/PrinterName$", oPrinter.name)
Call oInst.AddProperty("$MPElement[Name='Tasty.Printer.Monitoring.Windows2003.PrintServer.Printer']/PrintServerHost$", targetcomputer)
Call oInst.AddProperty("$MPElement[Name='Tasty.Printer.Monitoring.Windows2003.PrintServer.Printer']/PortName$", oPrinter.PortName)
Call oInst.AddProperty("$MPElement[Name='Tasty.Printer.Monitoring.Windows2003.PrintServer.Printer']/Location$", oPrinter.Location)
Call oInst.AddProperty("$MPElement[Name='Tasty.Printer.Monitoring.Windows2003.PrintServer.Printer']/Model$", oPrinter.DriverName)
Call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", TargetComputer)
Call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", oPrinter.name)
Call oDiscoveryData.AddInstance(oInst)
End If
Next