1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
| On Error Resume Next
Dim strComputer, strExcelPath, objExcel, objSheet, k, objGroup
Dim objWMIService, colItems, ErrState, Sheet
'Sheet = spreadsheet page, k = row in sheet
Sheet = 1
k = 2
strComputer = InputBox ("Please type the print server name to check, " & vbCrLf & _
"Else enter ALL for all CC print servers", "Server Name","CCPS01")
if strComputer = "" then
WScript.quit
end if
strExcelPath = InputBox ("Please enter the path to save file to: ", "File path", "d:\extractmopier\")
strExcelPath = strExcelPath & "Printers_" & strComputer & ".xls"
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
' Bind to Excel object.
On Error Resume Next
Set objExcel = CreateObject("Excel.Application")
If Err.Number <> 0 Then
On Error GoTo 0
Wscript.Echo "Excel application not found."
Wscript.Quit
End If
On Error GoTo 0
' Create a new workbook.
objExcel.Workbooks.Add
'Change this to fit your server situation
Select Case UCase(strComputer)
Case "ALL"
PrintServer("CCPS01")
Sheet = Sheet + 1
PrintServer("IRGFS01")
Sheet = Sheet + 1
PrintServer("CCFLDR01")
Case Else
PrintServer(strComputer)
End Select
Function PrintServer(strComputer)
k=2
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Printer",,48)
' Bind to worksheet.
Set objSheet = objExcel.ActiveWorkbook.Worksheets(Sheet)
objSheet.Name = strComputer
' Populate spreadsheet cells with printer attributes.
objSheet.Cells(1, 1).Value = "SERVEUR"
objSheet.Cells(1, 2).Value = "Name"
objSheet.Cells(1, 3).Value = "ShareName"
objSheet.Cells(1, 4).Value = "DriverName"
objSheet.Cells(1, 5).Value = "Location"
objSheet.Cells(1, 6).Value = "PortName"
objSheet.Cells(1, 7).Value = "Published"
objSheet.Cells(1, 8).Value = "Queued"
objSheet.Cells(1, 9).Value = "Shared"
For Each objItem in colItems
'put error code into human readable form
Select Case objItem.DetectedErrorState
Case 4
ErrState = "Out of Paper"
Case 5
ErrState = "Toner low"
Case 6
ErrState = "Printing"
Case 9
ErrState = "Offline"
Case Else
ErrState = objItem.DetectedErrorState
End Select
'populate the row with this printer's data
objSheet.Cells(k, 1).Value = strComputer
objSheet.Cells(k, 2).Value = objItem.Name
objSheet.Cells(k, 3).Value = objItem.ShareName
objSheet.Cells(k, 4).Value = objItem.DriverName
objSheet.Cells(k, 5).Value = objItem.Location
objSheet.Cells(k, 6).Value = objItem.PortName
objSheet.Cells(k, 7).Value = objItem.Published
objSheet.Cells(k, 8).Value = objItem.Queued
objSheet.Cells(k, 9).Value = objItem.Shared
k = k + 1
Next
' Format the spreadsheet.
objSheet.Range("A1:M1").Font.Bold = True
objSheet.Select
objSheet.Range("A2").Select
objExcel.ActiveWindow.FreezePanes = True
objExcel.Columns(3).ColumnWidth = 25
objExcel.Columns(5).ColumnWidth = 25
objExcel.Columns(6).ColumnWidth = 10
objExcel.Columns(8).ColumnWidth = 25
objExcel.Columns(1).ColumnWidth = 20
objExcel.Columns(9).ColumnWidth = 14
objExcel.Columns(2).ColumnWidth = 15
End Function
' Save the spreadsheet and close the workbook.
objExcel.ActiveWorkbook.SaveAs strExcelPath
objExcel.ActiveWorkbook.Close
' Quit Excel.
objExcel.Application.Quit
' Clean Up
Set objUser = Nothing
Set objGroup = Nothing
Set objSheet = Nothing
Set objExcel = Nothing
WScript.Echo "Printer listing is done" |
Partager