Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

VBScript: Map Printers based on computer group in Active Directory

Posted on 2006-03-30
6
Medium Priority
?
418 Views
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
0
Comment
Question by:ebizdatacom
4 Comments
 
LVL 23

Expert Comment

by:TheCleaner
ID: 16337355
This is really something to be done based on the Location field

See here:

http://technet2.microsoft.com/WindowsServer/en/Library/f33624bc-7518-4c2d-8f73-8a3d4571dae91033.mspx


0
 
LVL 16

Expert Comment

by:mdiglio
ID: 16338279
Hello,
If you wanted to try it with vbscript review this webpage.
http://www.rlmueller.net/freecode1.htm

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

Accepted Solution

by:
Kevin Hays earned 1000 total points
ID: 16338495
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

msgbox(strGroup)

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.

kshays
0
 
LVL 7

Assisted Solution

by:Cherukuri30
Cherukuri30 earned 1000 total points
ID: 16345822
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?
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

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

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…
Scenerio: You have a server running Server 2003 and have applied a retail pack of Terminal Server Licenses.  You want to change servers or your server has crashed and you need to reapply the Terminal Server Licenses. When you enter the 16-digit lic…
Integration Management Part 2
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

580 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