VonPitter 0 Newbie Poster

Hi I have a script for a user community that needs access to resources by department. Some users have member ship to multiple resources so I have sorted them out by "Printers" and "Shares".


*note not all printers are mapped as of yet

I am looking for someone to review this script and let me know if there is a better/more efficient way of doing this.

Option Explicit Dim objNetwork, objUser, CurrentUser
Dim strGroup
DIM strDriveLetter1, strDriveLetter2, strDriveLetter3, strDriveLetter4, strDriveLetter5
Dim strRemotePath1, strRemotePath2, strRemotePath3, strRemotePath4, strRemotePath5, strRemotePath6, strRemotePath7, strRemotePath8, strRemotePath9, strRemotePath10, strRemotePath11, strRemotePath12, strRemotePath13, strRemotePath14
Dim strUNCPrinter1, strUNCPrinter2, strUNCPrinter3, strUNCPrinter4, strUNCPrinter5, strUNCPrinter6, strUNCPrinter7, strUNCPrinter8, strUNCPrinter9, strUNCPrinter10, strUNCPrinter11, strUNCPrinter12, strUNCPrinter13, strUNCPrinter14, strUNCPrinter15, strUNCPrinter16, strUNCPrinter17, strUNCPrinter18, strUNCPrinter19
Dim bForce, bUpdateProfile

strDriveLetter1 = "Q:"
strDriveLetter2 = "R:"
strDriveLetter3 = "S:"

strRemotePath1 = "\\rdcits01\Share"
strRemotePath2 = "\\rdcits01\ISO"
strRemotePath3 = "\\rdcits01\AP-Share"
strRemotePath4 = "\\rdcits01\AR-Share"
strRemotePath5 = "\\rdcits01\CS-Share"
strRemotePath6 = "\\rdcits01\DC-Share"
strRemotePath7 = "\\rdcits01\HR-Share"
strRemotePath8 = "\\rdcits01\HT-Share"
strRemotePath9 = "\\rdcits01\FI-Share"
strRemotePath10 = "\\rdcits01\IP-Share"
strRemotePath11 = "\\rdcits01\IT-Share"
strRemotePath12 = "\\rdcits01\MK-Share"
strRemotePath13 = "\\rdcits01\RT-Share"
strRemotePath14 = "\\rdcits01\SA-Share"

strUNCPrinter1 = "\\rdcits01\RDCOSP01"
strUNCPrinter2 = "\\rdcits01\RDCOSP02"
strUNCPrinter3 = "\\rdcits01\RDCOSP03"
strUNCPrinter4 = "\\rdcits01\RDCOSP04"
strUNCPrinter5 = "\\rdcits01\"
strUNCPrinter6 = "\\rdcits01\"
strUNCPrinter7 = "\\rdcits01\"
strUNCPrinter8 = "\\rdcits01\"
strUNCPrinter9 = "\\rdcits01\"
strUNCPrinter10 = "\\rdcits01\"
strUNCPrinter11 = "\\rdcits01\"
strUNCPrinter12 = "\\rdcits01\"
strUNCPrinter13 = "\\rdcits01\"
strUNCPrinter14 = "\\rdcits01\"
strUNCPrinter15 = "\\rdcits01\"
strUNCPrinter16 = "\\rdcits01\"
strUNCPrinter16 = "\\rdcits01\"
strUNCPrinter17 = "\\rdcits01\"
strUNCPrinter18 = "\\rdcits01\"
strUNCPrinter19 = "\\rdcits01\"

Const HRFileGroup = "cn=HR_File_Access"
Const APFileGroup = "cn=AP_File_Access"
Const ARFileGroup = "cn=AR_File_Access"
Const CSFileGroup = "cn=CS_File_Access"
Const FIFileGroup = "cn=FI_File_Access"
Const HTFileGroup = "cn=HT_File_Access"
Const IPFileGroup = "cn=IP_File_Access"
Const ITFileGroup = "cn=IT_File_Access"
Const MKFileGroup = "cn=MK_File_Access"
Const RTFileGroup = "cn=RT_File_Access"
Const SAFileGroup = "cn=SA_File_Access"
Const DCFileGroup = "cn=DC_File_Access"
Const HRPrinterGroup = "cn=HR_Printers"
Const APPrinterGroup = "cn=AP_Printers"
Const ARPrinterGroup = "cn=AR_Printers"
Const CSPrinterGroup = "cn=CS_Printers"
Const FIPrinterGroup = "cn=FI_Printers"
Const HTPrinterGroup = "cn=HT_Printers"
Const IPPrinterGroup = "cn=IP_Printers"
Const ITPrinterGroup = "cn=IT_Printers"
Const MKPrinterGroup = "cn=MK_Printers"
Const RTPrinterGroup = "cn=RT_Printers"
Const SAPrinterGroup = "cn=SA_Printers"
Const DCPrinterGroup = "cn=DC_Printers"

Set objNetwork = CreateObject("WScript.Network")
Set objUser = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & objUser.UserName)
strGroup = LCase(Join(CurrentUser.MemberOf))
bForce = "True"
bUpdateProfile = "True"

on error resume next

' REMOVES ALL NETWORK DRIVES
objNetwork.RemoveNetworkDrive strDriveLetter1, bForce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter2, bForce, bUpdateProfile
objNetwork.RemoveNetworkDrive strDriveLetter3, bForce, bUpdateProfile

' REMOVES ALL PRINTERS
objNetwork.RemovePrinterConnection strUNCPrinter1, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter2, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter3, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter4, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter5, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter6, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter7, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter8, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter9, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter10, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter11, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter12, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter13, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter14, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter15, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter16, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter17, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter18, bForce, bUpdateProfile
objNetwork.RemovePrinterConnection strUNCPrinter19, bForce, bUpdateProfile

' ADDS PRINTERS THAT ARE AVAILABLE FOR ALL USERS
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.AddWindowsPrinterConnection strUNCPrinter2
objNetwork.AddWindowsPrinterConnection strUNCPrinter3
objNetwork.AddWindowsPrinterConnection strUNCPrinter4

' EXTRA PRINTERS FOR SPECIFIC GROUPs
if InStr(strGroup, HRPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
Elseif InStr(strGroup, APPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
Elseif InStr(strGroup, ARPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
Elseif InStr(strGroup, CSPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
Elseif InStr(strGroup, FIPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
Elseif InStr(strGroup, HTPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
Elseif InStr(strGroup, IPPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
Elseif InStr(strGroup, ITPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter1
Elseif InStr(strGroup, MKPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
Elseif InStr(strGroup, RTPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
Elseif InStr(strGroup, SAPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
Elseif InStr(strGroup, DCPrinterGroup) then
objNetwork.AddWindowsPrinterConnection strUNCPrinter1
objNetwork.SetDefaultPrinter strUNCPrinter2
end if

' SETTING ALL NETWORKDRIVES THAT ARE AVAILABLE FOR ALL USERS
objNetwork.MapNetworkDrive strDriveLetter1, strRemotePath1
objNetwork.MapNetworkDrive strDriveLetter2, strRemotePath2

' ADD DRIVES FOR SPECIFIC GROUPs
if InStr(strGroup, APFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath3
Elseif InStr(strGroup, ARFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath4
Elseif InStr(strGroup, CSFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath5
Elseif InStr(strGroup, DCFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath6
Elseif InStr(strGroup, HRFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath7
Elseif InStr(strGroup, HTFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath8
Elseif InStr(strGroup, FIFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath9
Elseif InStr(strGroup, IPFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath10
Elseif InStr(strGroup, ITFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath11
Elseif InStr(strGroup, MKFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath12
Elseif InStr(strGroup, RTFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath13
Elseif InStr(strGroup, SAFileGroup) then
objNetwork.MapNetworkDrive strDriveLetter3, strRemotePath14
end if

WScript.Quit

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.