Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Working on a project for an experiential learning class and well... I got asked to take care of the logon script, we're not ready to fully implement it yet, and I myself am a novice with scripts, but I tried and this is what I have. I am wondering if someone that is knowledgeable could take a look over and point out any mistakes-I can do more research as to why its wrong if I know what to look for.

Thanks for any help.

The goal of this script is to detect which group the user is a part of and then give the proper shares for the department. Payroll will have access to every department's "Payroll" share.

Department Key: HR, Accounting=ACT, Payroll=PYR, IT, Admin=AD, Production=PRD, Custodial=CST



Const ACT_GROUP = "cn=Accounting"
Const AD_GROUP = "cn=Admin"
Const CST_GROUP = "cn=Custodial"
Const HR_GROUP = "cn=Human Resources"
Const IT_GROUP = "cn=IT"
Const PYR_GROUP = "cn=Payroll"
Const PRD_GROUP = "cn=Production"



Set wshNetwork = CreateObject("WScript.Network")


Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" &
ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))

If InStr(strGroups, ACT_GROUP) Then

wshNetwork.MapNetworkDrive "N:",
"\\FileServer\Accounting\Department\"
wshNetwork.MapNetworkDrive "M:",
"\\FileServer\Accounting\Users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "O:",
"\\FileServer\Accounting\ACTPayroll\"

ElseIf InStr(strGroups, AD_GROUP) Then

wshNetwork.MapNetworkDrive "N:",
"\\FileServer\Admin\Department\"
wshNetwork.MapNetworkDrive "M:",
"\\FileServer\Admin\Users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "O:",
"\\FileServer\Admin\ADPayroll\"

ElseIf InStr(strGroups, CST_GROUP) Then

wshNetwork.MapNetworkDrive "N:",
"\\FileServer\Custodial\Department\"
wshNetwork.MapNetworkDrive "M:",
"\\FileServer\Custodial\Users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "O:",
"\\FileServer\Custodial\CSTPayroll\"

ElseIf InStr(strGroups, HR_GROUP) Then

wshNetwork.MapNetworkDrive "g:",
"\\FileServer\Human Resources\Department\"
wshNetwork.MapNetworkDrive "M:",
"\\FileServer\Human Resources\Users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "O:",
"\\FileServer\Human Resources\HRPayroll\"

ElseIf InStr(strGroups, IT_GROUP) Then

wshNetwork.MapNetworkDrive "g:",
"\\FileServer\IT\Department\"
wshNetwork.MapNetworkDrive "M:",
"\\FileServer\IT\Users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "O:",
"\\FileServer\IT\ITPayroll\"

ElseIf InStr(strGroups, PYR_GROUP) Then

wshNetwork.MapNetworkDrive "g:",
"\\FileServer\Payroll\Department\"
wshNetwork.MapNetworkDrive "M:",
"\\FileServer\Payroll\Users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "O:",
"\\FileServer\Payroll\PYRPayroll\"

wshNetwork.MapNetworkDrive "Q:",
"\\FileServer\Accounting\ACTPayroll\"
wshNetwork.MapNetworkDrive "R:",
"\\FileServer\Admin\ADPayroll\"
wshNetwork.MapNetworkDrive "S:",
"\\FileServer\Custodial\CSTPayroll\"
wshNetwork.MapNetworkDrive "T:",
"\\FileServer\Human Resources\HRPayroll\"
wshNetwork.MapNetworkDrive "U:",
"\\FileServer\IT\ITPayroll\"
wshNetwork.MapNetworkDrive "V:",
"\\FileServer\Production\PRDPayroll\"

ElseIf InStr(strGroups, PRD_GROUP) Then

wshNetwork.MapNetworkDrive "g:",
"\\FileServer\Production\Department\"
wshNetwork.MapNetworkDrive "M:",
"\\FileServer\Production\Users\" & wshNetwork.UserName
wshNetwork.MapNetworkDrive "O:",
"\\FileServer\Production\PRDPayroll\"

End If 
share|improve this question

1 Answer 1

Does it have to be done with a logon script? If using Group Policy Preferences is an option it is probably preferred. This way you can do it with a nice GUI and target it to groups the same way. Also it maps name to GUID so if a group name changes it will still work (not so much in a script unless you remember to change the name there also). Additionally you have the ability to see possible errors that occur in a workstation's Event Logs when this processes during logon. This gives a nice overview: Using Group Policy Preferences to Map Drives Based on Group Membership

If you need it to be a script, does nested group membership matter? Perhaps check http://www.rlmueller.net/freecode2.htm for some good sample scripts.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.