I'm trying to create a script which will enable view every PC to Printer relationship across an entire domain of around 1200 machines. In theory I am looking for a script to be run so that it will publish all the information it finds into a text document so that we can use this to view which PCs are connected to which printers (Network/Local).
I am currently using a script (Listed Below) which requires me to enter the IP or PC name of the computer so that it can query that PC and provide the current PC Printer relationship of the current logged on user.
I am hoping to change this script with some help from someone so that it will query a collection of PCs based within a textfile or CSV.
Const ForAppending = 8
Const ForReading = 1
Dim objTextFile
Dim objWriteFile
Dim objCopyFSO
Dim objWriteFSO
Dim objCrisFSO
Dim StrNextLine
Dim PCNameList
Dim FolderCopyError
Const ForWriting = 2
Const adTypeBinary = 1
Const adTypeText = 2
Const adSaveCreateOverWrite = 2
Const adModeReadWrite = 3
Dim sTitle, WshNetwork, objPrinter, intDrive, intNetLetter
'Tool Bar title
sTitle = "List Printers"
Dim StrComputer
'Textbox which enables the user to enter the IP/PC name of the PC
strComputer = InputBox("Enter IP or name of computer to check for " & _
"printer list (leave blank to check " & _
"local system)." & vbcrlf & vbcrlf & "Remote " & _
"checking only from NT type OS to NT type OS " & _
"with same Admin level UID & PW", sTitle)
'If the textbox is left empty then it will exit the application
If IsEmpty(strComputer) Then WScript.Quit
strComputer = Trim(strComputer)
If strComputer = "" Then strComputer = "."
'Copy the files to each workstation
'Create a new file and rename here to run multiple instances of this script.
Set WshNetwork = CreateObject("WScript.Network")
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem",,48)
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objItem in colItems
UserName = objItem.UserName
arrUserName = Split(UserName, "\", -1, 1)
varUserName = arrUserName(1)
Next
filOutput = varUserName & "_printers.txt"
If objFSO.FileExists(filOutput) Then
objFSO.DeleteFile(filOutput)
End If
Set objOutputFile = objFSO.OpenTextFile (filOutput, ForAppending, True)
For Each objPrinter in colInstalledPrinters
strTest = Left(objPrinter.Name, 2)
objOutputFile.WriteLine(objPrinter.Name)
Next
'objOutputFile.Close
'added
Set objPrinter = WshNetwork.EnumPrinterConnections
'Set objOutputFile = objFSO.OpenTextFile (filOutput, ForAppending, True)
If objPrinter.Count = 0 Then
WScript.Echo "No Printers Mapped "
else
For intDrive = 0 To (objPrinter.Count -1) Step 2
intNetLetter = IntNetLetter +1
printer = "UNC Path " & objPrinter.Item(intDrive) & " = " & objPrinter.Item(intDrive +1) & " Printer : " & intDrive
objOutputFile.WriteLine(printer)
Next
end if
objOutputFile.Close
'added
varOpen = MsgBox("Do you want to view the printers?",36,"View File?")
If varOpen = vbYes Then
varCommand = "notepad " & filOutput
WshShell.Run varCommand,1,False
End If
Wscript.Sleep 1500
MsgBox "Printer mappings have been stored in '" & filOutput & "'.", 64, "Script Complete"
Wscript.Quit
This is the original link for the script: http://community.spiceworks.com/scripts/show/1145-list-printers-vbs-update
If anyone has any experience doing something similar to this, or been in a situation where you've needed to collect Printer to PC relationship data, I'd be grateful for your input on how best to combat this issue.