Solved

VBScript for finding/mapping all shared printers on a server

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

Join & Write a Comment

Suggested Solutions

A quick step-by-step overview of installing and configuring Carbonite Server Backup.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

760 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