vmamedov
asked on
Need a sample script to map network drives based on group membership
I am looking for a sample script to map network drives for users based on their membership
Lets say the security groups that I have are
1. ldrive
2. mdrive
3. vdrive
4. zdrive
the network shares are
1. \\server\legal
2. \\server\marketing
3. \\server\visual
4. \\server\budget
I need ONE script to apply to the top level OU so that depending on which group the user belogs to they get a certain drive letter
thanks in advance
Lets say the security groups that I have are
1. ldrive
2. mdrive
3. vdrive
4. zdrive
the network shares are
1. \\server\legal
2. \\server\marketing
3. \\server\visual
4. \\server\budget
I need ONE script to apply to the top level OU so that depending on which group the user belogs to they get a certain drive letter
thanks in advance
Or this, slightly more tuned to suit your needs:
'==============
Dim objFSO
Set objFSO = CreateObject("Scripting.Fi leSystemOb ject")
Dim objNetwork
Set objNetwork = CreateObject("WScript.Netw ork")
Dim objWinntUser
Set objWinntUser = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.UserName & ",user")
Dim strGroupToCheck, strGroupShare, strDrive, strShare
' Specity the group name, a colon symbol, and the network share
' in this case, the drive letter is taken as the first letter of the group name
arrGroupShares = Array( _
"ldrive;\\server\legal", _
"mdrive;\\server\marketing ", _
"vdrive;\\server\visual", _
"zdrive;\\server\budget" _
)
For Each strGroupShare In arrGroupShares
strGroupToCheck = Split(strGroupShare, ";")(0)
strDrive = Left(strGroupToCheck, 1)
strShare = Split(strGroupShare, ";")(1)
If IsMemberOfGroup(objNetwork .UserDomai n, objWinntUser, strGroupToCheck) = True Then
'MsgBox "You are a member of " & strGroupToCheck
If objFSO.DriveExists(strDriv e) = True Then objNetwork.RemoveNetworkDr ive strDrive, True, True
objNetwork.MapNetworkDrive strDrive, strShare, True, True
ElseIf IsMemberOfGroup(objNetwork .UserDomai n, objWinntUser, strGroupToCheck) = False Then
'MsgBox "You are NOT a member of " & strGroupToCheck
ElseIf IsMemberOfGroup(objNetwork .UserDomai n, objWinntUser, strGroupToCheck) = "Error" Then
'MsgBox "There was no group found called " & strGroupToCheck
End If
Next
Function IsMemberOfGroup(strUserDom ain, objUser, strGroup) 'the user is a member of a specified group
IsMemberOfGroup = False
Dim objGroup
On Error Resume Next
Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
If Err.Number Then
IsMemberOfGroup = "Error"
Else
IsMemberOfGroup = objGroup.IsMember(objUser. ADsPath)
'MsgBox objUser.ADsPath
End If
End Function
'==============
Regards,
Rob.
'==============
Dim objFSO
Set objFSO = CreateObject("Scripting.Fi
Dim objNetwork
Set objNetwork = CreateObject("WScript.Netw
Dim objWinntUser
Set objWinntUser = GetObject("WinNT://" & objNetwork.UserDomain & "/" & objNetwork.UserName & ",user")
Dim strGroupToCheck, strGroupShare, strDrive, strShare
' Specity the group name, a colon symbol, and the network share
' in this case, the drive letter is taken as the first letter of the group name
arrGroupShares = Array( _
"ldrive;\\server\legal", _
"mdrive;\\server\marketing
"vdrive;\\server\visual", _
"zdrive;\\server\budget" _
)
For Each strGroupShare In arrGroupShares
strGroupToCheck = Split(strGroupShare, ";")(0)
strDrive = Left(strGroupToCheck, 1)
strShare = Split(strGroupShare, ";")(1)
If IsMemberOfGroup(objNetwork
'MsgBox "You are a member of " & strGroupToCheck
If objFSO.DriveExists(strDriv
objNetwork.MapNetworkDrive
ElseIf IsMemberOfGroup(objNetwork
'MsgBox "You are NOT a member of " & strGroupToCheck
ElseIf IsMemberOfGroup(objNetwork
'MsgBox "There was no group found called " & strGroupToCheck
End If
Next
Function IsMemberOfGroup(strUserDom
IsMemberOfGroup = False
Dim objGroup
On Error Resume Next
Set objGroup = GetObject("WinNT://" & strUserDomain & "/" & strGroup & ",group")
If Err.Number Then
IsMemberOfGroup = "Error"
Else
IsMemberOfGroup = objGroup.IsMember(objUser.
'MsgBox objUser.ADsPath
End If
End Function
'==============
Regards,
Rob.
ASKER
Rob, as always you come up with exactly what I am looking for.
just to double check, this script removed the drive letters first? then maps the ones in thescript?
also can you be more specific as to how to customize this script? where do i specify which drive letter i want to use, where do i specify which group to look at, and also where to i specify which network share to map?
i also would like to get rid of all message boxes
again thanks in advance
just to double check, this script removed the drive letters first? then maps the ones in thescript?
also can you be more specific as to how to customize this script? where do i specify which drive letter i want to use, where do i specify which group to look at, and also where to i specify which network share to map?
i also would like to get rid of all message boxes
again thanks in advance
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will try this out tomorrow and report back. You have been a great help
Thanks
Thanks
ASKER
Rob,
I have implemented the script but its not giving me the error below
-------------------------- -
Windows Script Host
-------------------------- -
Script: C:\Documents and Settings\user\Desktop\mapp ingdrives. vbs
Line: 32
Char: 13
Error: The specified network password is not correct.
Code: 80070056
Source: WSHNetwork.MapNetworkDrive
-------------------------- -
OK
-------------------------- -
My line 32 is this
objNetwork.MapNetworkDrive strDrive, strShare, True, True
Thanks in advance
I have implemented the script but its not giving me the error below
--------------------------
Windows Script Host
--------------------------
Script: C:\Documents and Settings\user\Desktop\mapp
Line: 32
Char: 13
Error: The specified network password is not correct.
Code: 80070056
Source: WSHNetwork.MapNetworkDrive
--------------------------
OK
--------------------------
My line 32 is this
objNetwork.MapNetworkDrive
Thanks in advance
Change that line from
objNetwork.MapNetworkDrive strDrive, strShare, True, True
to
objNetwork.MapNetworkDrive strDrive, strShare, True
objNetwork.MapNetworkDrive
to
objNetwork.MapNetworkDrive
Oh you've posted a new question for this....oh well..... I'm wondering if you've got some sort of cached credentials to a network resource....
Please follow the instructions in this article:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/usercpl_manage_passwords.mspx
to check if you have any cached passwords, and remove those that are for the same resource as the server you are trying to map a drive to.....
Regards,
Rob.
Please follow the instructions in this article:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/usercpl_manage_passwords.mspx
to check if you have any cached passwords, and remove those that are for the same resource as the server you are trying to map a drive to.....
Regards,
Rob.
ASKER
thank you chandru/rob for all your help
chandru, your solution was it, it solved the problem
rob, thank you for the original script and all the modifications that you have done
i will give full credit to rob on this post and give chandru full credit on the other post that i have opened regarding the specific error message.
again thanks for your help
if you both dont mind i have opened a another post regarding a different issue, if you can take a look at https://www.experts-exchange.com/questions/22970085/Need-sample-script-to-add-exchange-profile-to-all-users.html
chandru, your solution was it, it solved the problem
rob, thank you for the original script and all the modifications that you have done
i will give full credit to rob on this post and give chandru full credit on the other post that i have opened regarding the specific error message.
again thanks for your help
if you both dont mind i have opened a another post regarding a different issue, if you can take a look at https://www.experts-exchange.com/questions/22970085/Need-sample-script-to-add-exchange-profile-to-all-users.html
ASKER
rob was great and answered all my questions and the script worked.
ASKER