Thank you all for your help. I got the script to FINALLY work the way I wanted it to!! I might not be the easiest way and I'm still gonna explore other options, but until then I can say I did it!! The script as is won't make any ACL changes, it will just display the command lines. The actual commands are REMed out until futher testing! Thanks again!!
code:
BREAK ON
$DIR=F:\
SHELL "CMD.EXE /E:1024 /C DIR $DIR *. /AD /B /N > $DIR\DIRS.TXT"
Open(2,"$DIR\DIRS.TXT",4)
WRITELINE (2,"999999999")
CLOSE(2)
$INDEX2 = 0
$COUNT2 = 0
$index = 0 ; This index is used to count directories
$count = 0 ; This count is used to determine how many directories have been changed
SHELL "CMD.EXE /E:1024 /C CACLS $DIR > $DIR\CACLS.TXT"
$DIRLOC = $DIR
Open(1,"$DIR\CACLS.TXT",4)
WRITELINE (1,"THEEND")
CLOSE(1)
Open(1,"$DIR\CACLS.TXT",2)
Open(2,"$DIR\DIRS.TXT",2)
GOTO READACL
:SUBS
$COUNT2 = $COUNT2 + 1
$INDEX2 = $INDEX2 + 1
; This section reads each line of DIRS.TXT file with the directory information in it.
$D = ReadLine(2)
IF $D = "999999999"
Goto Done
ENDIF
; This secition will take the output file with the ACL information
; and wrote THEEND at the end of it to mark the end of the file
$DIRLOC='$DIR'+'$D'
? "$DIRLOC"
$shellstring2='cacls ' + '"$DIRLOC"'+ ' >' + ' "$DIRLOC' + '\CACLS.TXT"'
? "$SHELLSTRING2"
shell '%COMSPEC% /e:1024 /c '+$shellstring2
Open(1,'$DIRLOC' + \CACLS.TXT,4)
WRITELINE (1,"THEEND")
CLOSE(1)
Open(1,$DIRLOC + \CACLS.TXT,2)
; This section reads each line of the CACLS.TXT file with the ACL information in it.
; If the line has D01\ in it, the program will extract the user name or group name
; associated with D01\ and make it the $NAMEGRP variable
:READACL
$X = ReadLine(1)
IF $X = "THEEND"
CLOSE(1)
DEL '$DIRLOC' + '\CACLS.TXT'
Goto SUBS
Endif
IF INSTR ("$X", "EVERYONE")
$Account = split(split($X,":")[0],"\")
$NAMEGRP = LTRIM($Account[0])
GOTO PERMISSION
ENDIF
$S = LEN($DIRLOC + 1)
IF INSTR ("$X", "D01\") <> 0
$userperm=LTRIM(substr($X,$S))
$userperm=split($userperm,':')
$user=$userperm[0]
if instr($user,'\')
$user=split($user,'\')
$NAMEGRP=$user[1]
ENDIF
GOTO PERMISSION
ELSE
GOTO COUNT
ENDIF
:PERMISSION
$P = SUBSTR($X, LEN(RTRIM($X)), 1)
IF $P='N' OR $P='R' OR $P='W' OR $P='C' OR $P='F'
; This section will take the $NAMEGRP variable and add an ACL for the same user or group
; in the BIO domain. Giving that user or group None, Read, Write, Change or Full Control.
$shellstring='cacls ' + '$DIRLOC'+ ' /E /g' + ' BIO\' + '$NAMEGRP' + ':' + '$P'
; shell '%COMSPEC% /e:1024 /c '+$shellstring
? "$shellstring"
ENDIF
:COUNT
$count = $count + 1 ;increase the count of directories
$index = $index + 1 ;increment index for next pass
goto READACL ;loop and read next ACL
CLOSE (1)
CLOSE (2)
:Done
CLOSE (2)
DEL $DIR + 'DIRS.TXT'
? "Done!"
? ""