В настоящее время мы работаем над сценарием, который считывает информацию о текущих пользователях с сервера ActiveDirectory и проверяет группы, чтобы узнать, какие принтеры им нужны.
Мы столкнулись с проблемой, которую пытались обойти, используя встроенную функцию InStr
, где пытались сопоставить имя группы в строке, например:
cn=GG_RoomA1,dc=Security Group cn=GG_RoomA2,dc=Security Group ...
Эта строка доходит до GG_Room13
'EDC Room A1
If InStr(strGroup, lcase(GG_RoomA1)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA1_P002765"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmA1_P002765"
End if
Переменные следующие:
strGroup
| большая строка групп
GG_RoomA1
является постоянным набором и имеет значение cn=cn=GG_RoomA1
Проблема заключается в том, что если вы являетесь членом группы GG_RoomA10
, вы также получите GG_RoomA1
.
Есть ли способ, которым мы можем специально сопоставить только одну группу со следующими факторами,
Весь код здесь.
Option Explicit
'On error resume next
'Declare Variables
Dim objNetwork, objUser, CurrentUser, strGroup, objFSO, Printers, i
'Declare Constant Groups for Printer Locations
Const GG_RoomA1 = "cn=GG_RoomA1"
Const GG_RoomA2 = "cn=GG_RoomA2"
Const GG_RoomA4 = "cn=GG_RoomA4"
Const GG_RoomA6 = "cn=GG_RoomA6"
Const GG_RoomA7 = "cn=GG_RoomA7"
Const GG_RoomA8 = "cn=GG_RoomA8"
Const GG_Room_CopiersA6_A8 = "cn=GG_Room_CopiersA6-A8"
Const GG_RoomA9 = "cn=GG_RoomA9"
Const GG_RoomA10 = "cn=GG_RoomA10"
Const GG_RoomL1 = "cn=GG_RoomL1"
Const GG_RoomL7 = "cn=GG_RoomL7"
Const GG_RoomL9 = "cn=GG_RoomL9"
Const GG_RoomC1 = "cn=GG_RoomC1"
Const GG_RoomC3 = "cn=GG_RoomC3"
Const GG_Room2 = "cn=GG_Room2"
Const GG_Room3 = "cn=GG_Room3"
Const GG_Room4_5 = "cn=GG_Room4&5"
Const GG_Room6 = "cn=GG_Room6"
Const GG_Room8_9 = "cn=GG_Room8&9"
Const GG_Room10L = "cn=GG_Room10L"
Const GG_Room10R = "cn=GG_Room10R"
Const GG_Room11 = "cn=GG_Room11"
Const GG_Room12 = "cn=GG_Room12"
Const GG_Room12A = "cn=GG_Room12A"
Const GG_Room12B = "cn=GG_Room12B"
Const GG_Room13 = "cn=GG_Room13"
Const GG_Room14_15 = "cn=GG_Room14&15"
Const GG_Room16 = "cn=GG_Room16"
Const GG_Room17 = "cn=GG_Room17"
Const GG_Room_FRAnnexeA = "GG_Room_FRAnnexeA"
Const GG_Room_FRAnnexeB = "GG_Room_FRAnnexeB"
Const GG_Room_FRAnnexeC = "GG_Room_FRAnnexeC"
Const GG_Room_FR02 = "GG_Room_FR02"
Const GG_Room_FR05 = "GG_Room_FR05"
Const GG_Room_FR10 = "GG_Room_FR10"
Const GG_Room_FR11 = "GG_Room_FR11"
Const GG_Room_FR13 = "GG_Room_FR13"
Const GG_Room_FR14 = "GG_Room_FR14"
Const GG_Room_FR16 = "GG_Room_FR16"
Const GG_Room_Ruiz = "GG_Room_Ruiz"
Const GG_Room_NLAdmin = "GG_Room_NLAdmin"
Const GG_Room_NLManagers = "GG_Room_NLManagers"
Const GG_Room_NLShared = "GG_Room_NLShared"
Const GG_Room_NLSupport = "GG_Room_NLSupport"
Const GG_Room_Shepwell = "GG_Room_Shepwell"
Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)
Set objFSO = CreateObject("Scripting.FileSystemObject")
strGroup = LCase(Join(CurrentUser.MemberOf))
'Remove all Network printers but not local printers
Set Printers = objNetwork.EnumPrinterConnections
For i = 0 to Printers.Count - 1 Step 2
If Left(ucase(Printers.Item(i+1)),2) = "\\" Then
'WScript.Echo Printers.Item(i+1)
objNetwork.RemovePrinterConnection Printers.Item(i+1)
End If
Next
'EDC Room A1
If InStr(strGroup, lcase(GG_RoomA1)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA1_P002765"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmA1_P002765"
End if
'EDC Room A2
If InStr(strGroup, lcase(GG_RoomA2)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA2_P002280"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA2_ARM207"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmA2_P002280"
End if
'EDC Room A4
If InStr(strGroup, lcase(GG_RoomA4)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA4_P002012"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA4_P002175"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA4_P000169"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA4_P002874"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmA4_P002012"
End if
'EDC Room A5 and A6
If InStr(strGroup, lcase(GG_RoomA6)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA5_P001710"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA5_P000640"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA6_P002821"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA6_MX3100N"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmA6_P002821"
End if
'EDC Room A7
If InStr(strGroup, lcase(GG_RoomA7)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA7_P000804"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA7_P002241"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA7_ARM350"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmA7_P002241"
End if
'EDC Room A8
If InStr(strGroup, lcase(GG_RoomA8)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA8_P001720"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA8_P002820"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA8_P002861"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA8_MX550U"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmA8_P002820"
End if
'EDC Room A6-A8 Copiers
If InStr(strGroup, lcase(GG_Room_CopiersA6_A8)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA6_MX3100N"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA8_MX550U"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA7_ARM350"
End if
'EDC Room A9
If InStr(strGroup, lcase(GG_RoomA9)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA9_P002011"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA9_P002819"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmA9_P002819"
End if
'EDC Room A10
If InStr(strGroup, lcase(GG_RoomA10)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA10_P002827"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmA6_MX3100N"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmA10_P002827"
End if
'EDC Room L1
If InStr(strGroup, lcase(GG_RoomL1)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmL1_IRC2880"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmL1_P000474"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmL1_P002420"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmL1_P002420"
End if
'EDC Room L7
If InStr(strGroup, lcase(GG_RoomL7)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmL7_P002603"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmL7_P002260"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmL7_MX363N"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmL7_P002603"
End if
'EDC Room L9
If InStr(strGroup, lcase(GG_RoomL9)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmL9_P000930"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmL9_P000930"
End if
'EDC Room C1
If InStr(strGroup, lcase(GG_RoomC1)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmC1_P000476"
'objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\???"
'objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\???"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmC1_P000476"
End if
'EDC Room C3
If InStr(strGroup, lcase(GG_RoomC3)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRmC3_P002828"
'objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\???"
'objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\???"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRmC3_P002828"
End if
'EDC Room 2
If InStr(strGroup, lcase(GG_Room2)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm2_P000229"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRM2_P000442"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm2_P000229"
End if
'EDC Room 3
If InStr(strGroup, lcase(GG_Room3)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm3_P001736"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm3_P001736"
End if
'EDC Room 4 & 5
If InStr(strGroup, lcase(GG_Room4_5)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm4&5_P000751"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRM4&5_P001904"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm4&5_P000751"
End if
'EDC Room 6
If InStr(strGroup, lcase(GG_Room6)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm6_P002806"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRM6_P002562"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm6_P002806"
End if
'EDC Room 8 & 9
If InStr(strGroup, lcase(GG_Room8_9)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm8&9_P001775"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm8&9_P001775"
End if
'EDC Room 10L
If InStr(strGroup, lcase(GG_Room10L)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm10_P002379"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm10_P002380"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm10_P002764"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm10_P002380"
End if
'EDC Room 10R
If InStr(strGroup, lcase(GG_Room10R)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm10_P002379"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm10_P002380"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm10_P002764"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm10_P002379"
End if
'EDC Resource Room (Room 11)
If InStr(strGroup, lcase(GG_Room11)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm11_MX4501N"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm11_MX700U"
End if
'EDC Room 12
If InStr(strGroup, lcase(GG_Room12)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm12_P002224"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm12_P002224"
End if
'EDC Room 12A
If InStr(strGroup, lcase(GG_Room12A)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm12A_P000786"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm12A_P000792"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm12A_P000786"
End if
'EDC Room 12B
If InStr(strGroup, lcase(GG_Room12B)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm12B_P002781"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm12B_P002781"
End if
'EDC Room 13
If InStr(strGroup, lcase(GG_Room13)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm13_P001784"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm13_P002818"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm13_P002818"
End if
'EDC Room 14 & 15
If InStr(strGroup, lcase(GG_Room14_15)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRM14&15_P002782"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm14&15_P002782"
End if
'EDC Room 16
If InStr(strGroup, lcase(GG_Room16)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm16_P001360"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm16_P001512"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm16_P001512"
End if
'EDC Room 17
If InStr(strGroup, lcase(GG_Room17)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm17_P001045"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCRm17_P001936"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm16_P001512"
End if
'Field Road Admin
'IS THIS NEEDED - IS FR16 the same thing
'If InStr(strGroup, lcase(GG_Room???)) Then
'objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAdmin_P000230"
'objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAdmin_P000525"
'objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCRm16_P001512"
'End if
'Field Road AnnexeA SEN
If InStr(strGroup, lcase(GG_Room_FRAnnexeA)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAnnexe_P002809"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAnnexe_P002805"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAnnexeSEN_ARM256"
objNetwork.SetDefaultPrinter "\\edw-sr-img\FRAnnexe_P002805"
End if
'Field Road AnnexeB DISABILITY
If InStr(strGroup, lcase(GG_Room_FRAnnexeB)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAnnexe_P002312"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAnnexeDIS_ARM256"
objNetwork.SetDefaultPrinter "\\edw-sr-img\FRAnnexe_P002312"
End if
'Field Road AnnexeC LAC
If InStr(strGroup, lcase(GG_Room_FRAnnexeC)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAnnexeLAC_P000991"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAnnexeLAC_P001050"
objNetwork.SetDefaultPrinter "\\edw-sr-img\FRAnnexeLAC_P001050"
End if
'Field Road FR02
If InStr(strGroup, lcase(GG_Room_FR02)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRMain_MX3100N"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRMain_MX363N"
End if
'Field Road FR05
If InStr(strGroup, lcase(GG_Room_FR05)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRMain_P002436"
objNetwork.SetDefaultPrinter "\\edw-sr-img\FRMain_P002436"
End if
'Field Road FR10
If InStr(strGroup, lcase(GG_Room_FR10)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRRm10_P000438"
objNetwork.SetDefaultPrinter "\\edw-sr-img\FRRm10_P000438"
End if
'Field Road FR11
If InStr(strGroup, lcase(GG_Room_FR11)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRRm11_P002013"
objNetwork.SetDefaultPrinter "\\edw-sr-img\FRRm11_P002013"
End if
'Field Road FR13
If InStr(strGroup, lcase(GG_Room_FR13)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRRm13_P001049"
objNetwork.SetDefaultPrinter "\\edw-sr-img\FRRm13_P001049"
End if
'Field Road FR14
If InStr(strGroup, lcase(GG_Room_FR14)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRRm14_P001041"
objNetwork.SetDefaultPrinter "\\edw-sr-img\FRRm14_P001041"
End if
'Field Road FR16
If InStr(strGroup, lcase(GG_Room_FR16)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAdmin_P000230"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRAdmin_P000525"
objNetwork.SetDefaultPrinter "\\edw-sr-img\FRAdmin_P000230"
End if
'Field Road RUIZ
If InStr(strGroup, lcase(GG_Room_Ruiz)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRRuiz_P001072"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRRuiz_P001867"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\FRRuiz_MX283N"
objNetwork.SetDefaultPrinter "\\edw-sr-img\FRRuiz_P001867"
End if
'New Leaf Admin
If InStr(strGroup, lcase(GG_Room_NLAdmin)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCNL_IRC3580"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCNL_P002871"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCNL_P002871"
End if
'New Leaf Managers
If InStr(strGroup, lcase(GG_Room_NLManagers)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCNL_P002306"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCNL_P002206"
End if
'New Leaf Shared
If InStr(strGroup, lcase(GG_Room_NLShared)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCNL_IRC3580"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCNL_IRC3580"
End if
'New Leaf Support
If InStr(strGroup, lcase(GG_Room_NLSupport)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\EDCNL_P002016"
objNetwork.SetDefaultPrinter "\\edw-sr-img\EDCNL_P002016"
End if
'Shepwell
If InStr(strGroup, lcase(GG_Room_Shepwell)) Then
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\SHEP_P000436"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\SHEP_P002017"
objNetwork.AddWindowsPrinterConnection "\\edw-sr-img\SHEP_P002017"
objNetwork.SetDefaultPrinter "\\edw-sr-img\SHEP_P000436"
End if
Dim answer
answer=MsgBox("Printer Script is Complete!",0,"Confirmation")
'End Printer Script
WScript.Quit