VBScript: Map Printers based on computer group in Active Directory

Posted on 2006-03-30
Last Modified: 2010-04-18
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
Question by:ebizdatacom
    LVL 23

    Expert Comment

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

    See here:

    LVL 16

    Expert Comment

    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.
    LVL 16

    Accepted Solution

    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\
    '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.

    LVL 7

    Assisted Solution

    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?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    This may not be a text book method to resolve VSS backup issues but it seemed to have worked on few of the Windows 2003 servers we had issues while performing a Volume Shadow Copy backup. If you have issues while performing a shadow copy backup usin…
    ADCs have gained traction within the last decade, largely due to increased demand for legacy load balancing appliances to handle more advanced application delivery requirements and improve application performance.
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…

    758 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

    11 Experts available now in Live!

    Get 1:1 Help Now