Script to map home drive and department folder

Hi,

I have windows 2008 domain environment and a file server. I have requirement of mapping HOme drive and department drives using logon script, How I can automate this.

I have folder structure as below:

\\fileServer\HomeDrive\$Username$

\\fileserver\accounts
\\fileserver\HR
\\fileserver\purchase

etc

I have security group like accounts, HR, purchase and users in it.

When a user "John" from HR department logs in, he must me mapped with
H:\  = \\fileserver\home\john
Z:\  = \\fileserver\HR

When a user "Mary" from accounts department logs in, she must me mapped with
H:\  = \\fileserver\home\Mary
Z:\  = \\fileserver\accounts

How I can do this using any script.
kolathaya123Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lee W, MVPTechnology and Business Process AdvisorCommented:
Ideally you should be using Group Policy Preferences to map network drives.  This Directory Services team blog illustrates how to use Group Policy preferences for this purpose:
http://blogs.technet.com/b/askds/archive/2009/01/07/using-group-policy-preferences-to-map-drives-based-on-group-membership.aspx

If you must use a script, Microsoft has a blog on doing so with VBS - the script from that blog is excepted below:
On Error Resume Next

Set objSysInfo = CreateObject("ADSystemInfo")
Set objNetwork = CreateObject("Wscript.Network")

strUserPath = "LDAP://" & objSysInfo.UserName
Set objUser = GetObject(strUserPath)

For Each strGroup in objUser.MemberOf
    strGroupPath = "LDAP://" & strGroup
    Set objGroup = GetObject(strGroupPath)
    strGroupName = objGroup.CN

    Select Case strGroupName
        Case "Finance Users"
            objNetwork.MapNetworkDrive "X:", "\\atl-fs-01\finance"
        
        Case "Human Resource Users" 
            objNetwork.MapNetworkDrive "X:", "\\atl-fs-01\hr"

        Case "Manufacturing Users"
            objNetwork.MapNetworkDrive "X:", "\\atl-fs-01\manufacturing"

        Case "Shipping and Receiving Users"
            objNetwork.MapNetworkDrive "X:", "\\atl-fs-01\shipping"
    End Select
Next

Open in new window


Or you could use a batch script using the net user /domain command and additional parameters as the excerpted script below from this blog points out:

net user /domain %username% | find "MYOB Users"
if not errorlevel = 1 (
net use m: \\JCC-SBS\MYOB
)

Open in new window

http://clintboessen.blogspot.com/2011/02/ifmemberexe-doesnt-work-windows.html
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.