Find Those Printers

When decommisioning an older server in the environment, it is essential that all the former services are moved off it. This includes the existing applications (including databases), file shares and printer shares. Unfortunately there is no easy way to capture who is mapped to each of the pritner shares. Outside simply monitoring printer traffic, or visiting each desktop, Windows (AFIK) has no method of tracking this.

Hence another script. This script queries the active computer for all printers, then exports the 'resource name' (port) and share name to a CSV in a specific location.

' Source: <a href="http://www.devguru.com/Technologies/wsh/quickref/wshnetwork_EnumPrinterConnections.html
'
" title="http://www.devguru.com/Technologies/wsh/quickref/wshnetwork_EnumPrinterConnections.html
'">http://www.devguru.com/Technologies/wsh/quickref/wshnetwork_EnumPrinterC...</a> Compiled by Eric Woodford

'
change this path to match your current environment.
strLogPath = "\\servername\admin\printermappings"


Const forReading = 1
Const ForWriting = 2
Const ForAppending = 8

'get environment variable username
set shell = WScript.CreateObject( "WScript.Shell" )
username = shell.ExpandEnvironmentStrings("%USERNAME%")
Computername = shell.ExpandEnvironmentStrings("%COMPUTERNAME%")
set shell = nothing

auditfile = strLogPath &"\"&username&"_"&computername&".csv"

set fs = CreateObject("Scripting.FilesystemObject")
Fs.CreateTextFile(AuditFile)
set f = fs.OpenTextFile (AuditFile, ForWriting, True)

strText = "Resource name,Printer name" & vbcrlf
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set clPrinters = WshNetwork.EnumPrinterConnections
For i = 0 to clPrinters.Count -1
    if i mod 2 <> 0 then
        strtext = strtext & clPrinters.Item(i) & vbcrlf
    else
        strtext = strtext & clPrinters.Item(i) & ","
    end if
Next

f.writeline strText
f.close

set fs=nothing

AttachmentSize
enum printers.zip699 bytes

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <blockquote> <center> <hr> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <drupal6>, <html>, <java>, <javascript>, <php>, <posh>.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.