Modified tour script a bit hope you don’t mind.
I removed the GoSub stuff. GoSub (and GoTo) should not be used in best practice because they make spaghetti code that is almost impossible to read and the flow of the script gets hard to follow.
Untested but the script below should work.
It first deletes the drives before mapping them because users can delete a drive mapping and map some other drive. It uses the /persistent option to also delete the drive is it has been mapped persistent. If the mapping of a drive failed it writes a line to the log file with error codes and workstation name.
Code:
; *** Login Script for all domain users ***
$rc = Open (1, "\\recordingserver\Errorlogs\" + @WKSTA + "_ERR.TXT", 5)
CLS
; Everyone gets the G drive
Use g: /delete /persistent
Use g: "\\nas\apps"
If @ERROR
$rc = WriteLine (1, "Everyone. " + @WKSTA + " has problems mapping the G drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
; HR is the only group that doesn't get the J drive
If NOT InGroup("HR")
Use j: /delete /persistent
Use j: "\\server2\Drive"
If @ERROR
$rc = WriteLine (1, "All users but HR. " + @WKSTA + " has problems mapping the J drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
EndIf
; Begin mapping drives for the individual groups
If InGroup("Group1")
Use p: /delete /persistent
Use q: /delete /persistent
Use r: /delete /persistent
Use p: "\\callserver1\ccrecordings$"
If @ERROR
$rc = WriteLine (1, "Group1. " + @WKSTA + " has problems mapping the P drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
Use q: "\\callserver2\ccrecordings$"
If @ERROR
$rc = WriteLine (1, "Group1. " + @WKSTA + " has problems mapping the Q drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
Use r: "\\callserver3\ccrecordings$"
If @ERROR
$rc = WriteLine (1, "Group1. " + @WKSTA + " has problems mapping the R drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
EndIf
If InGroup("Legal")
Use r: /delete /persistent
Use r: "\\nas\legal"
If @ERROR
$rc = WriteLine (1, "Legal. " + @WKSTA + " has problems mapping the R drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
EndIf
If InGroup("IT")
Use r: /delete /persistent
Use w: /delete /persistent
Use y: /delete /persistent
Use r: "\\remotenas\software"
If @ERROR
$rc = WriteLine (1, "IT group. " + @WKSTA + " has problems mapping the R drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
Use w: "\\ITServer\Drive"
If @ERROR
$rc = WriteLine (1, "IT group. " + @WKSTA + " has problems mapping the W drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
Use y: "\\ITServer\install$"
If @ERROR
$rc = WriteLine (1, "IT group. " + @WKSTA + " has problems mapping the Y drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
EndIf
If InGroup("HR")
Use u: /delete /persistent
Use u: "\\nas\hr"
If @ERROR
$rc = WriteLine (1, "HR group. " + @WKSTA + " has problems mapping the U drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
EndIf
If InGroup("scangroup")
Use s: /delete /persistent
Use s: "\\nas\scan"
If @ERROR
$rc = WriteLine (1, "Scangroup. " + @WKSTA + " has problems mapping the U drive." + @CRLF)
$rc = WriteLine (1, @ERROR + " " + @SERROR + @CRLF)
EndIf
EndIf
$rc = Close (1)