Explain the script

can someone comments this script for me. line by line.?
I appreciate it.

On Error Resume Next

Dim GroupList
Set fso = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
Set WshNetwork = WScript.CreateObject("WScript.Network")

GetGroupInfo()

LogonPath = fso.GetParentFolderName(WScript.ScriptFullName)
'**************************************Group Mappings Based on Grouplist.csv*********************************
If fso.FileExists(logonpath&"\Grouplist.csv") Then
   Set grplist = Fso.OpenTextFile(logonpath&"\Grouplist.csv")
   ' make File into an Array
   aGroup = Split(grplist.Readall,vbcrlf)
   For I = 0 to UBound(GroupList) ' Check Every Group Membership the user is in (populated into Grouplist)
      grpname = Grouplist(i)
      For x = 0 to UBound(aGroup) ' Read the entire CSV to make sure all drives are mapped for each Group
         mapline = agroup(x)
         If InStr(LCase(mapline),LCase(grpname)) Then ' If you're in the group
            mapline = Mid(mapline,InStr(mapline,",")+1) ' Remove the GroupName from the line
            Drive = Left(mapline,InStr(mapline,",")-1) ' Extract Drive Letter
            Path = Mid(mapline,InStr(mapline,",")+1) ' Extract the path

            If (fso.DriveExists(drive) <> True) and (Drive<>"!!") Then ' If The Drive is not already mapped
               WshNetwork.MapNetworkDrive drive,path,true ' Map The Drive
               wscript.sleep 1000
            End If

        If Drive = "!!" then
               WSHNetwork.AddWindowsPrinterConnection Path
               wscript.sleep 1000
            end if

         End If
      Next
   Next
End If


Sub GetGroupInfo
Set UserObj = GetObject("WinNT://" & wshNetwork.UserDomain & "/" & WshNetwork.UserName)
Set Groups = UserObj.groups

For Each Group In Groups
GroupCount = GroupCount + 1
Next

ReDim GroupList(GroupCount -1)
i = 0
For Each Group In Groups
GroupList(i) = Group.Name
i = i + 1
Next
End Sub
jskfanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi, I hope this clarifies it enough for you:

'====================
' Turn error checking off. This means that the script will Not
' stop when it encounters an error. It will continue with the Next
' of code.  This can cause problems if you don't know why a script
' is not working.
On Error Resume Next

' Declare a variable for use later
Dim GroupList
' Create an object that allows us to work with the file system
Set fso = CreateObject("Scripting.FileSystemObject")
' Create an object that allows us to use Shell comamnds
Set WshShell = CreateObject("WScript.Shell")
' Create an object that allows us to use networking comamnds
Set WshNetwork = WScript.CreateObject("WScript.Network")

' Call a Sub Procedure called GetGroupInfo(), which is written below
' The procedure populates the GroupList array, which will hold the
' current group memberships of the user
GetGroupInfo()

' Retrieve the Parent folder name of the location where the script
' file is running from.
LogonPath = fso.GetParentFolderName(WScript.ScriptFullName)

'**************************************Group Mappings Based on Grouplist.csv*********************************
' Check if the file "Grouplist.csv" exists in the parent folder
If fso.FileExists(logonpath&"\Grouplist.csv") Then
      ' If the file exists, open it. By using Set grplist, then grplist becomes a pointer
      ' to the open file, meaning we can read from it.
   Set grplist = Fso.OpenTextFile(logonpath&"\Grouplist.csv")
   ' make File into an Array, using the Split function. This makes each element
   ' of the array become one line from the file, because it has been split by vbCrLf (newline character).
   ' aGroup is the array of groups that a user *should* be a member of
   ' GroupList is the array of groups that a user is *currently* a member of
   aGroup = Split(grplist.Readall,vbcrlf)
   For I = 0 to UBound(GroupList) ' Check Every Group Membership the user is in (populated into Grouplist)
      grpname = Grouplist(i)
      For x = 0 to UBound(aGroup) ' Read the entire CSV to make sure all drives are mapped for each Group
         mapline = agroup(x)
         ' Check if the user is already a member of the groups from the CSV
         If InStr(LCase(mapline),LCase(grpname)) Then ' If you're in the group
            mapline = Mid(mapline,InStr(mapline,",")+1) ' Remove the GroupName from the line
            Drive = Left(mapline,InStr(mapline,",")-1) ' Extract Drive Letter
            Path = Mid(mapline,InStr(mapline,",")+1) ' Extract the path

            If (fso.DriveExists(drive) <> True) and (Drive<>"!!") Then ' If The Drive is not already mapped
               WshNetwork.MapNetworkDrive drive,path,true ' Map The Drive
               wscript.sleep 1000
            End If

            ' In the CSV file, the path that needs to be mapped can also be identified
            ' as !! for the drive letter, which means it's not a drive, it is a printer to be mapped
        If Drive = "!!" then
               WSHNetwork.AddWindowsPrinterConnection Path
               wscript.sleep 1000
            end if

         End If
      Next
   Next
End If


' This sub procedure populates the GroupList array, which will hold the
' current group memberships of the user
Sub GetGroupInfo
' Bind to the current user object on the domain
Set UserObj = GetObject("WinNT://" & wshNetwork.UserDomain & "/" & WshNetwork.UserName)
' Return a collection of the groups the user is a member of
Set Groups = UserObj.groups

' Go through each group
For Each Group In Groups
GroupCount = GroupCount + 1
Next

' Resize the array to fit each group name
ReDim GroupList(GroupCount -1)
i = 0
For Each Group In Groups
GroupList(i) = Group.Name
i = i + 1
Next
End Sub
'===================

Regards,

Rob.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.