Script to add Printer when user is added to specific group in AD

I am trying to write a SB script that will allow me to add a printer when a user is added to a specifc group in active Directory.

Refering to my Code below what I would like to happen is when a user is added to:

Group1  --> Map Printer KM_5050
Group2 --> Add Printer KM_3035
Group3 --> Add Printer KM_2550

when a user is added to group 1 and 2 they would receive both printers

Is there anyone who might be able to tell me where my code went askew?
<job id="vbs">
<script language="VBScript">
Set WshNetwork = WScript.CreateObject("WScript.Network")
Dim strUserLocation, strLocationType, strUserDomain, strFollettGroup, strUserAppServer, strUserDesktop
strUserDomain = "Domain.lcl"
On Error Resume Next
'***** New Printer Map for Kyocera Main Office
If getGroupMembership(strUserDomain,WshNetwork.UserName,"Group1") Then
            WshNetwork.AddWindowsPrinterConnection "\\server3\Kyocera KM-5050 (main office)"
else If
'***** New Printer Map for Kyocera for ASP
If getGroupMembership(strUserDomain,WshNetwork.UserName,"Group2") Then
            WshNetwork.AddWindowsPrinterConnection "\\Server3\Kyocer KM-3035 (ASP)"
else If
'***** New Printer Map for Kyocera for Shared Houseing
If getGroupMembership(strUserDomain,WshNetwork.UserName,"Group3") Then
            WshNetwork.AddWindowsPrinterConnection "\\Server3\Kyocera KM-2550 (SH)"
Function getGroupMembership (strDomain,strUser,strGroupMem)
	suserobj = "windows://" & strDomain & "/" & strUser
	set suser = getobject(suserobj)
	For Each x in suser.groups
		If = strGroupMem Then
			getGroupMembership = TRUE
			Exit Function
		End If
	getGroupMembership = FALSE
End Function
Set wshNetwork = Nothing

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Try this instead...
Edit line 16, 18 and 20 to match your group names.

If this does not map the printers, then the printer share name might be different.
Set WSHNetwork = WScript.CreateObject("WScript.Network")
On Error Resume Next
Domain = WSHNetwork.UserDomain
UserName = ""
While UserName = ""
	UserName = WSHNetwork.UserName
	MyGroups = GetGroups(Domain, UserName)
Set objUser = GetObject("WinNT://" & Domain & "/" & UserName)
For Each objGroup In objUser.Groups
	select Case objGroup.Name
			MapPrinter "\\server3\Kyocera KM-5050 (main office)", "FALSE"
			MapPrinter "\\Server3\Kyocer KM-3035 (ASP)>", "FALSE"
			MapPrinter "\\Server3\Kyocera KM-2550 (SH)", "FALSE"
	end select
Sub MapPrinter(sPrinterPath,sPrinterDefault)
	On Error Resume Next
	WSHNetwork.AddWindowsPrinterConnection sPrinterPath
	WScript.Sleep 300
	If sPrinterDefault = "1" Or sPrinterDefault = UCase("TRUE") Then
		WSHNetwork.SetDefaultPrinter sPrinterPath
	End If
End Sub

Open in new window


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
itvizionAuthor Commented:
Thanks this was exactly what i needed
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
VB Script

From novice to tech pro — start learning today.