jlepre
asked on
VBS Script to Map Printer Based on Group Membership
Hello,
I am trying to create a VBS Logon Script to map printers based on group membership. I have two groups and two printers called PrinterA and PrinterB. When I run the script I do not get any printer mappings or any error messages. Any ideas on why this does not work?
Thanks in advance.
I am trying to create a VBS Logon Script to map printers based on group membership. I have two groups and two printers called PrinterA and PrinterB. When I run the script I do not get any printer mappings or any error messages. Any ideas on why this does not work?
Thanks in advance.
Const PrinterA ="cn=PrinterA"
Const PrinterB = "cn=PrinterB"
Set wshNetwork = CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))
If InStr(strGroups, PrinterA) Then
wshNetwork.AddWindowsPrinterConnection "\\W2k8-INT\PrinterA"
wshNetwork.AddWindowsPrinterConnection "\\W2k8-INT\PrinterB"
wshNetWork.SetDefaultPrinter "\\W2k8-INT\PrinterA"
ElseIf InStr(strGroups, PrinterB) Then
wshNetwork.AddWindowsPrinterConnection "\\W2k8-INT\PrinterB"
wshNetwork.AddWindowsPrinterConnection "\\W2k8-INT\PrinterA"
wshNetWork.SetDefaultPrinter "\\W2k8-INT\PrinterB"
End If
so you would have 2 case statements
case "PrinterA" if that's the name of the group you want to map the A printer,
call MapPrinterA()
case "PrinterB"
call MapPrinterB()
and your
map printer subroutines will have the code to map the printers
case "PrinterA" if that's the name of the group you want to map the A printer,
call MapPrinterA()
case "PrinterB"
call MapPrinterB()
and your
map printer subroutines will have the code to map the printers
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the help, I am in a training class today, I will give this a try later this afternoon.
ASKER
When I run the script I get the following error attached:
vbs-error.JPG
vbs-error.JPG
ASKER
I deleted the End If at Line 41 and all works well. Thanks.
try this construct..
instead of mapping drives, put in your map network printer statements
this is just an example. but you should be able to modify it to your needs
Open in new window