Active Directory User Login Script

Published 08-22-2017 20:20:23

On Error Resume Next

Dim WSHShell, WSHNetwork, DomainString, UserObj, GroupObj

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

'Execute commandline tools if defined
ExitCode = ESHShell.Run("net use \\Server\share password /USER:UID /Persistent:yes",0,vbTrue)

'Map drives needed by all users

'Now check for group membershops 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)
		Case "DOMAIN USERS"

		Case "OMA-SA-GENERAL"
			WSHNetwork.RemoveNetworkDrive "S:", True, True
			WSHNetwork.MapNetworkDrive "S:", "\\SERVER\GeneralShare", True
			WSHNetwork.RemoveNetworkDrive "P:", True, True
			WSHNetwork.MapNetworkDrive "P:", "\\SERVER\GeneralShare", True
			WSHNetwork.RemoveNetworkDrive "A:", True, True
			WSHNetwork.MapNetworkDrive "A:", "\\SERVER\GeneralShare", True
		Case "OMA-SA-ACCOUNTING"
			WSHNetwork.RemoveNetworkDrive "Z:", True, True
			WSHNetwork.MapNetworkDrive "Z:", "\\SERVER\Accounting", True
		Case "LIN-SA-GENERAL"
			WSHNetwork.RemoveNetworkDrive "S:", True, True
			WSHNetwork.MapNetworkDrive "S:", "\\SERVER\Path", True
			WSHNetwork.RemoveNetworkDrive "P:", True, True
			WSHNetwork.MapNetworkDrive "P:", "\\SERVER\Path", True
			WSHNetwork.RemoveNetworkDrive "Z:", True, True
			WSHNetwork.MapNetworkDrive "Z:", "\\SERVER\Path", True
	End Select
Next

'Clean Up Memory We Used
set UserObj = nothing
set GroupObj = nothing
set WSHNetwork = nothing
set DomainString = nothing
set WSHShell = nothing

'quit the script
WScript.Quit