Need a VBscript that maps network drives depending on user OU memership

Hi there.  We are running AD 2000 with XP user pc's. I am in need of a vbscript that maps network drives depending on user OU membership. For example: map drive "R" as \\server\abc is the user is part of the customer support OU. I know nothing about scripting so any help would be greatly appreciated.

Thanks,

Akkis
akkisthubanAsked:
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.

kristjanpkCommented:
Hi Akkis

Here is a sample script of how I usually do this, you can paste this into a textfile (with .vbs extension of course):


On Error Resume Next

Set objNet = CreateObject("WScript.Network")
Set objShell = WScript.CreateObject("WScript.Shell")

'==== Map network drives for GroupName1

If IsMember("GroupName1") <> 0 Then
objNet.RemoveNetworkDrive "X:",1
objNet.MapNetworkDrive "X:", "\\servername1\sharename",True
End If

'==== Map network drives for GroupName2

'If IsMember("GroupName2") <> 0 Then
'objNet.RemoveNetworkDrive "Y:",1
'objNet.MapNetworkDrive "Y:", "\\servername1\sharename2",True
'End If

'==== Check Group Function

Private Function IsMember(groupName)

  Set netObj = CreateObject("WScript.Network")
  domain = netObj.UserDomain
  user = netObj.UserName
  flgIsMember = false
  Set userObj = GetObject("WinNT://" & domain & "/" & user & ",user")
  For Each grp In userObj.Groups
    If grp.Name = groupName Then
      flgIsMember = true
      Exit For
    End If
  Next
  IsMember = flgIsMember
  Set userObj = Nothing

End Function


All you have to do is rename GroupName1/GroupName2 with the groups you want.  Along with the \\servername1\sharename.
Hope this helps.

Kristjan

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
RobSampsonCommented:
Here is a version that checks the parent OU (the uppermost OU) and maps a drive accordingly:
'=================
Set objSysInfo = CreateObject("ADSystemInfo")
strName = objSysInfo.UserName

arrUserName = Split(strName, ",")
arrOU = Split(arrUserName(1), "=")
strUserOU = arrOU(1)

Set objNetwork = CreateObject("WScript.Network")

Select Case strUserOU
    Case "Customer Support"
        objNetwork.MapNetworkDrive "Y:", "\\servername1\sharename1",True
    Case "Finance"
        objNetwork.MapNetworkDrive "Y:", "\\servername1\sharename2",True
    Case "Human Resources"
        objNetwork.MapNetworkDrive "Y:", "\\servername2\sharename3",True
    Case Else
        ' do not map any drives
End Select
'=================

Regards,

Rob.
akkisthubanAuthor Commented:
Thanks guys. I'll give those a shot.
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
VB Script

From novice to tech pro — start learning today.