Badger Data Systems - Computer Network Services - Phone Systems

home products services faq company contact
 
   

Badger Data Systems - Home
Computer and Phone System Products
Computer Network Services - Phone System Services
Frequently Asked Questions
Badger Data Systems Info
Contact - Badger Data Systems

Badger Data Systems

 

Badger Data Systems, Inc.

816 Meadow Lane, Stevens Point, WI 54481

(715)346-1000

info@BadgerData.com

 

Welcome to Badger Data Systems Web Site

It's all about QoS...

QoS is Quality of Service. QoS ensures your computer network systems can handle today's high bandwidth needs including voice, data and video transmissions. QoS is what we provide ... (more)


Computer Nework Systems - Phone System Picture

 

The Last Logon Script You'll Ever Need

On this page are login scripts that will map users drives based on group membership.  While many scripts have been written to complete this task, those scripts have to be rewritten every time a new drive share is added, a server name changes or a different drive letter is used.  The script I’ve written does not require change because the script parses the server name, drive letter and share name directly from the group name.  For example: the Network Administrator can create a group called [MyServer_AnyShare_X] and any user that is a member of that group will have drive X: mapped to \\MyServer\AnyShare when they next logon.  I wrote two versions of the script.  The basic version works with users assigned directly to the map drives groups only while the longer script allows for nested groups and for excluding a user from a drive mapping.

Basic

Basic With Comments

Long Version with Support for Nested Groups

Instructions

1. Create an OU called DriveMaps. This OU can be anywhere in the hierarchy of your Active Directory.

2. Create the drive mapping groups in the DriveMaps OU and place users in groups. Example: Server1_Accounting_K to map K: to the \\Server1\Accounting share.

3. Copy the script below into a text file and save it with a VBS extension. Save the file to c:\windows\sysvol\sysvol\domainname\scripts.

4. Use group policy to run the logon script or configure the user profiles to run the script.

Basic Script

ON ERROR RESUME NEXT
'Purpose: The script when run will enumerate the groups
' that the user belongs to. If any of the groups
' are in a OU named {MapDrives} the script will
' parse the server name, share name and drive
' letter from the group name and will map the drive.
' The group lookup does not include nested groups.
'
'Usage: Create an OU Named {MapDrives}
' - Create a group named {SrvName_ShrName_i} where
' SrvName = File server name
' ShrName = Share Name on the server
' i = Drive Letter to Map
'
' Example: MyServer_AnyShr_X
' When run the script will map the drive
' \\MyServer\AnyShr to drive X: for all members
' of the group.
'
' - Add users to the the MapDrive group(s)
'
' Written by: Paul Raflik
' Badger Data Systems
' Paul@BadgerData.com
' 715-346-1000
'
' Copy Right (c) 2006 Paul M. Raflik, Sr.
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the copyright owner above has no warranty, obligations,
' or liability for such use.

'
'Last updated: 11/6/2006

*** Parse the Mapdrives Groups and Map the drive
'
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
For Each strGrpName In CurrentUser.MemberOf
If InStr(Lcase(strGrpName), LCase("drivemaps")) Then
FirstEquals = InStr(strGrpName, "=")
FirstUndln = InStr(strGrpName, "_")
SecondUndln = InStr(Firstundln + 1, strGrpName, "_")
SrvName = "\\" & Mid(strGrpName, FirstEquals + 1, FirstUndln - FirstEquals - 1) & "\"
ShrName = Mid(strGrpName, FirstUndln + 1, SecondUndln - FirstUndln - 1)
DrvLetter = Mid(strGrpName, SecondUndln + 1, 1) & ":"
wshNetwork.RemoveNetworkDrive DrvLetter
wshNetwork.MapNetworkDrive DrvLetter, SrvName & ShrName
End If
Next

Basic Script - Commented

'Purpose: The script when run will enumerate the groups
' that the user belongs to. If any of the groups
' are in a OU named {MapDrives} the script will
' parse the server name, share name and drive
' letter from the group name and will map the drive.
' The group lookup does not include nested groups.
'
'Usage: Create an OU Named {MapDrives}
' - Create a group named {SrvName_ShrName_i} where
' SrvName = File server name
' ShrName = Share Name on the server
' i = Drive Letter to Map
'
' Example: MyServer_AnyShr_X
' When run the script will map the drive
' \\MyServer\AnyShr to drive X: for all members
' of the group.
'
' - Add users to the the MapDrive group(s)
'
' Written by: Paul Raflik
' Badger Data Systems
' Paul@BadgerData.com
' 715-346-1000
'
' Copy Right (c) 2006 Paul M. Raflik, Sr.
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the copyright owner above has no warranty, obligations,
' or liability for such use.

'
'Last updated: 11/6/2006

'

ON ERROR RESUME NEXT

'*** Parse the Mapdrives Groups and Map the drive
'
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
'***
'*** Enumerate Group Memberships for user
'***
For Each strGrpName In CurrentUser.MemberOf
' ***
' *** Search group string for the work "DriveMaps" if it exists then map the drive.
' ***
If InStr(Lcase(strGrpName), LCase("drivemaps")) Then
' ***
' *** Find the location of the Equals Sign in the string. The server name starts
' *** at the next character after it.
' ***
FirstEquals = InStr(strGrpName, "=")
' ***
' *** Find the first underline character in the string. The server name ends
' *** one character before it. Sharename starts next character after
' ***
FirstUndln = InStr(strGrpName, "_")
' ***
' *** Find the second underline character in the string. The share name ends
' *** one character before it. Drice Letter is the next character after
' ***
SecondUndln = InStr(Firstundln + 1, strGrpName, "_")
' ***
' *** Assign server name, share name and drive letter to variables
' ***
SrvName = "\\" & Mid(strGrpName, FirstEquals + 1, FirstUndln - FirstEquals - 1) & "\"
ShrName = Mid(strGrpName, FirstUndln + 1, SecondUndln - FirstUndln - 1)
DrvLetter = Mid(strGrpName, SecondUndln + 1, 1) & ":"
' ***
' *** Disconnect Drive letter if already in use
' ***
wshNetwork.RemoveNetworkDrive DrvLetter
' ***
' *** Map Drive
' ***
wshNetwork.MapNetworkDrive DrvLetter, SrvName & ShrName
End If
Next

Long Version with Support for Nested Groups

'#################### MapDrivesV2.VBS ####################
'Purpose: The script when run will enumerate the groups
' that the user belongs to. If any of the groups
' are in a OU named {MapDrives} the script will
' parse the server name, share name and drive
' letter from the group name and will map the drive.
' The group lookup includes nested groups.
'
'Usage: Create an OU Named {MapDrives}
' - Create a group named {SrvName_ShrName_i} where
' SrvName = File server name
' ShrName = Share Name on the server
' i = Drive Letter to Map
'
' Example: MyServer_AnyShr_X
' When run the script will map the drive
' \\MyServer\AnyShr to drive X: for all members
' of the group.
'
' - Add users or other groups the the MapDrive group(s)
'
' To Exclude Users that are a memeber of a group from
' getting the map drive do the following:
' - Create a group named {X_SrvName_ShrName_i} where
' SrvName = File server name
' ShrName = Share Name on the server
' X = Drive Letter to Map
'
' Example: X_MyServer_AnyShr_X
' In the example if the Group {Accounting} was a member
' of the group {MyServer_AnyShr_X} and the user was also a
' member of {X_MyServer_AnySHr_X} then the script will not
' map the drive for that user. The {X_} exclude groups
' override the MapDrives groups.
'
' Written by: Paul Raflik
' Badger Data Systems
' Paul@BadgerData.com
' 715-346-1000
'
' Copy Right (c) 2006 Paul M. Raflik, Sr.
'
' You have a royalty-free right to use, modify, reproduce, and
' distribute this script file in any way you find useful, provided that
' you agree that the copyright owner above has no warranty, obligations,
' or liability for such use.

'
'Last updated: 11/6/2006
'
'##########################################################
'
'
'######################## Main() ##########################
'On Error Resume Next
' *** Declare Arrays ***
Dim AllGroups(1000) ' String Array of all the groups that the user belongs to.
Dim Stack(1000) ' String Array of the stack used to enumerate groups.
Dim strStackHist(1000) ' Stack history to prevent same groups from going to the
' stack more than once.
'
' *** Initialize Variables ***
intStackHist = 0 ' Integer Couter for the Stack history array
Count = 1 ' Integer Counter for the AllGrops array
i = 0 ' Integer coutner for Stack array
'
' *** Get list of groups that user is a direct member of.
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
For Each g In CurrentUser.MemberOf
i = i + 1
Stack(i) = g
intStackHist = intStackHist + 1
strStackHist(intStackHist) = g
AllGroups(Count) = g
Count = Count + 1
intPopHist
Next
'
' *** Enumerate Nested Group Memberships
'
Do While i <> 0
strGroup = PopStack()
Set objGroup = GetObject _
("LDAP://" & strGroup)
objGroup.GetInfo
arrMembersOf = objGroup.GetEx("memberOf")
For Each strMemberOf in arrMembersOf
If Not InAllG(strMemberOf) Then
AllGroups(Count) = strmemberof
Count = Count + 1
End If
if strGroup <> strmemberOF Then
Call PushStack(strMemberOF)
end if
Next
Erase arrMembersOf
Loop
'
' *** Parse the Mapdrives Groups and Map the drive
'
For k = 1 to Count - 1

strGrpName = AllGroups(k)
If InStr(Lcase(strGrpName), LCase("drivemaps")) Then
If LCase(Left(strGrpName,5)) <> LCase("CN=X_") Then
Xclude = False
For j = 1 to Count
strG = "CN=X_" & Right(strGrpName, Len(strGrpName)-3)
If strG = AllGroups(j) Then
Xclude = True
Exit For
End if
Next
If Xclude = False Then
FirstEquals = InStr(strGrpName, "=")
FirstUndln = InStr(strGrpName, "_")
SecondUndln = InStr(Firstundln + 1, strGrpName, "_")
SrvName = Mid(strGrpName, FirstEquals + 1, FirstUndln - FirstEquals - 1)
ShrName = Mid(strGrpName, FirstUndln + 1, SecondUndln - FirstUndln - 1)
DrvLetter = Mid(strGrpName, SecondUndln + 1, 1)
If Instr(DrvLettersUsed, DrvLetter) Then
' Wscript.echo "OOPS!, Already Mapped Drive " & DrvLetter
Else
DrvLetter = DrvLetter & ":"
SrvName = "\\" & Srvname & "\"
wshNetwork.RemoveNetworkDrive DrvLetter
wshNetwork.MapNetworkDrive DrvLetter, SrvName & ShrName
DrvLettersUsed = DrvLettersUsed & DrvLetter
End If
End If
End If
End If
Next
'###################### End Main() ########################
'
'
'##################### StackHist() ########################
'
'Purpose: Called by PushStack()
' Keeps track of all groups that are pushed on the
' stack so that the same group does not get enumerated
' more than once.
'
Private Function StackHist(strNewPush)
StackHist = False
For j = 1 to intStackHist
strOutx = strOutx & chr(13) & j & ": " & strStackHist(j)
If strNewPush = strStackHist(j) Then
StackHist = True
End If
Next
End Function
'################### End StackHist() ######################
'
'##################### PushStack() ########################
'
'Purpose: If a group is found to have groups as members then
' that group is put onto the stack to later be
' enumerated to determine if it also has group members.
'
sub PushStack(strPush)
If Not StackHist(strPush) Then
i = i + 1
Stack(i) = strPush
intStackHist = intStackHist + 1
strStackHist(intStackHist) = strPush
End If
End Sub
'################### End PushStack() #######################
'
'###################### PopStack() #########################
'
'Purpose: When the stack is popped the last group added to the
' stack is removed and is emumerated to determine if
' there are additional group members'
'
Function PopStack()
PopStack = Stack(i)
i = i - 1
End Function
'#################### End PopStack() #######################
'
'####################### InAllG() ##########################
'
'Purpose: Called by Main(). Used to determine if a group
' Has already been added to the AllGroups array
' to avoid duplicate entries.
'
Function InAllG(strIn)
InAllG = False
For m = 1 to Count - 1
if strIn = Allgroups(m) Then
InAllG = True
Exit Function
End If
Next
End Function
'####################### InAllG() ##########################


Serving These Central Wisconsin Communities and Surrounding Areas

Computer Network Services & Phone Systems

Stevens Point - Wausau - Marshfield - Waupaca -Schofield - Mosinee - Wisconsin Rapids - Shwano - Rhineladner - Amherst - Tomahawk - Plover - Merrill - Wood County - Marathon County - Portage County - Lincoln County - Waupaca County - Outagamie County - Winnebago County - Waushara County - Oneida County - Adams County - Marquette County

Computer Network Systems - Phone Systems - News
AVAYA Business Phone Systems
· Avaya Wins Best in VoiceCon for one-X Quick Edition ... (more)
· Avaya Leads Global Enterprise IP Telephony ... (more)
· Newsletter Archive

Computer Network Systems - Phone Systems - Links
· AVAYA
· Microsoft
· Extreme Networks
· Cisco
· GN Netcom
· Additional Resources


Computer Network Systems - Phone Systems - Specials
IP Office 406v2


  home · products · services · faq · the company · contact
© Copyright 2006 Badger Data Systems, Inc. All rights reserved.