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: http://www.devguru.com/Technologies/wsh/quickref/wshnetwork_EnumPrinterC...
' 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
| Attachment | Size |
|---|---|
| enum printers.zip | 699 bytes |
Comments
Post new comment