Solved

VBScript for finding/mapping all shared printers on a server

Posted on 2007-11-14
1
1,216 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Windows 2003 PDC Trust Root Certificate About to Expire 5 45
Group policy backup error 8 25
AD Account Lockout 22 39
PowerShell:  Add Header to Out-File 2 26
In this article, we will see the basic design consideration while designing a Multi-tenant web application in a simple manner. Though, many frameworks are available in the market to develop a multi - tenant application, but do they provide data, cod…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
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 …

867 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now