Solved

VBScript for finding/mapping all shared printers on a server

Posted on 2007-11-14
1
1,220 Views
Last Modified: 2010-05-18
We have 30+ sites each with its own Windows 2003 Server, under one domain.

I'm trying to write a VBS logon script that will find/map all printers shared off of their server. I'm trying to avoid using case statements (based upon group membership or the local server) and hard-coding in each printer for each site (some sites have two printers, some have five.) Call it laziness.

Ideally I'd be able to find the logon server (currently having it pull the %LOGONSERVER% variable to map some network drives anyway) then just grab a list of what's shared and map accordingly. Like "EnumPrinterConnections" just on the server.
0
Comment
Question by:Neil2526
1 Comment
 
LVL 4

Accepted Solution

by:
sbtec earned 500 total points
ID: 20284441
Hi. First Script shows you all published printers:
********************************************************
Const ADS_SCOPE_SUBTREE = 2

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCommand.ActiveConnection = objConnection
objCommand.CommandText = "Select printerName, serverName from " _    
    & " 'LDAP://DC=fabrikam,DC=com'  where objectClass='printQueue'"  
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
Set objRecordSet = objCommand.Execute
objRecordSet.MoveFirst

Do Until objRecordSet.EOF
    Wscript.Echo "Printer Name: " & objRecordSet.Fields("printerName").Value
    Wscript.Echo "Server Name: " & objRecordSet.Fields("serverName").Value
    objRecordSet.MoveNext
Loop
********************************************************


The second script shows you how to connect to a network printer. Now it should be easy to merge the scripts, so all printers found will be installed:
Set WshNetwork = CreateObject("WScript.Network")

Greetz from switzerland

WshNetwork.AddWindowsPrinterConnection "\\PrintServer1\Xerox300"
WshNetwork.SetDefaultPrinter "\\PrintServer1\Xerox300"
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question