I found this site through a Google search and markdmac's Login script seems to fit almost exactly what I am looking for. I did modify it a little to get rid of somethings I don't need.
A little background on the situation:
We have a domain called "CompanyA". In this domain, I created a new OU called "TestUsers" where I placed a test user named "Bob Villa" and also placed the test computer in this OU. I did make BVilla member of the Recruiting and Purchasing groups for testing purposes.
Our file storage server is "ServerA". The files are located on the Data (E
drive, with shared folders named "Users" and "Departments".
But instead of linking the GPO to the entire domain, I linked this particular login script to the TestUsers OU only. Perhaps this is my error?
I'm going to paste the modified script below, but when I login to the domain with this particular account, no drives are being mapped and I find no errors in the Event Viewer.
Any ideas?
'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' Copyright (c) 2003-2010
' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
' Maps and disconnects drives and printers
'
'==========================================================================
ON ERROR RESUME NEXT
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically grab the user's domain name
DomainString = Wshnetwork.UserDomain
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next
'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300
'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.
'Note alternate mapping code in Add-In section that allows
'friendly renaming of drive mappings
WSHNetwork.MapNetworkDrive "U:", "\\Renegade\Users\" & UserString,True
'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
For Each GroupObj In UserObj.Groups
'Force upper case comparison of the group names, otherwise this is case sensitive.
Select Case UCase(GroupObj.Name)
'Check for group memberships and take needed action
'In this example below, ADMIN and WORKERB are groups.
'Note the use of all upper case letters as mentioned above.
'Note also that the groups must be Global Groups.
Case "Purchasing"
WSHNetwork.MapNetworkDrive "R:", "\\Renegade\Departments\Recruiting",True
Case "Recruiting"
WSHNetwork.MapNetworkDrive "P:", "\\Renegade\Departments\Purchasing",True
End Select
Next
'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
'Quit the Script
wscript.quit
A little background on the situation:
We have a domain called "CompanyA". In this domain, I created a new OU called "TestUsers" where I placed a test user named "Bob Villa" and also placed the test computer in this OU. I did make BVilla member of the Recruiting and Purchasing groups for testing purposes.
Our file storage server is "ServerA". The files are located on the Data (E
But instead of linking the GPO to the entire domain, I linked this particular login script to the TestUsers OU only. Perhaps this is my error?
I'm going to paste the modified script below, but when I login to the domain with this particular account, no drives are being mapped and I find no errors in the Event Viewer.
Any ideas?
'==========================================================================
'
' NAME: LogonScript.vbs
'
' AUTHOR: Mark D. MacLachlan, The Spider's Parlor
' URL : ' Copyright (c) 2003-2010
' DATE : 4/10/2003
'
' COMMENT: Enumerates current users' group memberships in given domain.
' Maps and disconnects drives and printers
'
'==========================================================================
ON ERROR RESUME NEXT
Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path
Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")
'Automatically grab the user's domain name
DomainString = Wshnetwork.UserDomain
'Find the Windows Directory
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")
'Grab the user name
UserString = WSHNetwork.UserName
'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)
'Grab the computer name for use in add-on code later
strComputer = WSHNetwork.ComputerName
'Disconnect ALL mapped drives
Set clDrives = WshNetwork.EnumNetworkDrives
For i = 0 to clDrives.Count -1 Step 2
WSHNetwork.RemoveNetworkDrive clDrives.Item(i), True, True
Next
'Give the PC time to do the disconnect, wait 300 milliseconds
wscript.sleep 300
'Map drives needed by all
'Note the first command uses the user name as a variable to map to a user share.
'Note alternate mapping code in Add-In section that allows
'friendly renaming of drive mappings
WSHNetwork.MapNetworkDrive "U:", "\\Renegade\Users\" & UserString,True
'Now check for group memberships and map appropriate drives
'Note that this checks Global Groups and not domain local groups.
For Each GroupObj In UserObj.Groups
'Force upper case comparison of the group names, otherwise this is case sensitive.
Select Case UCase(GroupObj.Name)
'Check for group memberships and take needed action
'In this example below, ADMIN and WORKERB are groups.
'Note the use of all upper case letters as mentioned above.
'Note also that the groups must be Global Groups.
Case "Purchasing"
WSHNetwork.MapNetworkDrive "R:", "\\Renegade\Departments\Recruiting",True
Case "Recruiting"
WSHNetwork.MapNetworkDrive "P:", "\\Renegade\Departments\Purchasing",True
End Select
Next
'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
'Quit the Script
wscript.quit