VBScript: Map Printers based on computer group in Active Directory

I have a site that has several areas (ie front desk, reception, billing, nurses station,) and each area has a printer.  I have a script that I'm using that runs on the local W2K and XP workstations and maps specified printers and drive mappings.  I would like to improve on this though and have a script that maps a printer based on computer membership.  I'm very new to scripting and have pieced together the one I use from other folks kind examples online.  I have inputed part of my script below to give an idea as to what I'm looking for and how things are running now.

Currently I have something like...

Set objWSHNetwork = CreateObject("WScript.Network") 'create network object
strConnectString = "\\server\CanonS82"
strResult = objWSHNetwork.AddWindowsPrinterConnection(strConnectString)

I'd like an example script given what I have above thats something like this in concept...

If member of computergroup (front desk) then
Set objWSHNetwork = CreateObject("WScript.Network") 'create network object
strConnectString = "\\web_development\CanonS82"
strResult = objWSHNetwork.AddWindowsPrinterConnection(strConnectString)
end if

If member of computergroup (back office) then
Set objWSHNetwork = CreateObject("WScript.Network") 'create network object
strConnectString = "\\Server\HPLJ6"
strResult = objWSHNetwork.AddWindowsPrinterConnection(strConnectString)

Thank you in advance for all of your help.  I've learned a lot already, and am hoping that I can get an understandable answer to this problem.

Thank you
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

This is really something to be done based on the Location field

See here:


If you wanted to try it with vbscript review this webpage.

It contains scripts to check for group membership of users or computers.
There are several there so make sure you find the one that suits your needs the best.

Once you find one let us know if you need help placing it into your existing code.
Kevin HaysIT AnalystCommented:
Looks like the links will point you in the right direction.  I've got some scripts, but they map printers and shares based on security group memberships.  Only thing I see right off hand is you don't want to create an object for each condition you encounter.  Create it globally then just assign the strConnectString and strResult according to you case or if statement.

Here is a sample that might help you also.

Dim objNet, objADInfo, objUser                          'declare objects
Dim strGroup, strDrv, strDC, strFileServer            'declare string values
set objNet          = CreateObject("Wscript.Network")                    'create network object
set objADInfo     = CreateObject("ADSystemInfo")                        'create AD object
set objUser        = GetObject("LDAP://" & objADInfo.UserName)    'create user object

strDC                 = "\\srcadsfst\"      'string value containing server name
strFileServer      = "\\lnxsmbsars\"     'string value containing server name

'Drive letter mappings


'J = \\srcadsfst\IT
'K = \\srcadsfst\public
'X = \\lnxsmbsars\it
'y = \\lnxsmbsars\user.name
'z = \\lnxsmbsars\Public

strGroup = UCase(Join(objUser.MemberOf,vbCr)) 'combine all groups into an array


That's just part of a script, but the msgbox(strGroup) should list all groups the user belongs to.  You will have to modify to your needs though.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Cherukuri30Service EngineerCommented:
if isMember("groupname") then  
end if

isMember function will find whether the user using this logon script is existing in the specified group

is that you are looking for?
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.