Logon script

thenrich
thenrich used Ask the Experts™
on
I'd like to create a logon script so if username = 'x' then map these drives elseif username = 'Y' do these drives. What would the code for this look like? Would it be better to do in a conditional If statement of a case statement?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2013

Commented:
Do you have at least one 2008 or one Vista machine on your network?  If you do then I'd use group policy preferences for something like that.  The Item level targeting in GPP is great.  Some more on that here
http://blogs.technet.com/askds/archive/2009/01/07/using-group-policy-preferences-to-map-drives-based-on-group-membership.aspx
Thanks
Mike

Author

Commented:
We do not run 2008 or vista. Plus my users are not as neatly defined as 'groups' yet.
Microsoft has a great script example here:

http://technet.microsoft.com/en-us/library/cc758918%28WS.10%29.aspx

instead of using groups, you could go by ADSysInfo.UserName

Commented:
I crunched the script ahmad2121 referred to above for you.  By doing this you can simply add users to the group once you find more users with the same need rather than constantly tweaking your login script.

Hope this helps.

ou_dober

' Create a global group in AD and put user X in that group.
' Rename CN below to global group with user X
Const GROUP_X = "cn=GROUPX"
' Create a global group in AD and put user Y in that group.
' Rename CN below to global group with user Y
Const GROUP_Y = "cn=GROUPY"
 
' This is to setup the home user drive - remove REM (') if needed or change appropriately
' Set wshNetwork = CreateObject("WScript.Network")
' wshNetwork.MapNetworkDrive "h:","\\FileServer\Users\" & wshNetwork.UserName
 
' This is the LDAP connection to lookup user and see if their in groups above
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" &
ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))
 
If InStr(strGroups, GROUP_X) Then
' Copy and/or change line to map drives for users in group X as needed
    wshNetwork.MapNetworkDrive "g:", "\\FileServer\Engineering\"
' Copy and/or change line to map printers for users in group X as needed - remove REM (') if needed or change appropriately
'   wshNetwork.AddWindowsPrinterConnection "\\PrintServer\EngLaser"
'   wshNetwork.AddWindowsPrinterConnection "\\PrintServer\Plotter"
'   wshNetWork.SetDefaultPrinter "\\PrintServer\EngLaser"
ElseIf InStr(strGroups, GROUP_Y) Then
' Copy and/or change line to map drives for users in group Y as needed
    wshNetwork.MapNetworkDrive "g:", "\\FileServer\Finance\"
' Copy and/or change line to map printers for users in group Y as needed - remove REM (') if needed or change appropriately
'   wshNetwork.AddWindowsPrinterConnection "\\PrintServer\FinLaser"
'   wshNetWork.SetDefaultPrinter "\\PrintServer\FinLaser"
End If

Open in new window

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial