Jump to content

Folder/File auditing


Recommended Posts

I'm trying to figure out the best way to recursive search through one file (profile.ini) nested in each user's profile directory and compare an entry to the parent folder. If they match, move on, if they don't match, write that parent folder info to an updating text file.

I got a lot of help here last time and was hoping for the same again, or at least get pointed in the right direction. See below for a crude example of what the process would be.


Working Directory: D:\TSProfiles\
Full path: D:\TSProfiles\sentinel1705\windows\profile.ini

Within Profile.ini,

If CurrentWorkstation=Sentinel1705,

Goto Next folder

Else if

Write Sentinel1705 to Badfile.txt
Next

Link to comment
Share on other sites


Does TSProfiles contain only directories named with UserNames?

Is it likely that UserNames will be found elsewhere within the .ini file or that more than one UserName may appear in the same file?

Is the script being run locally/per machine or is this intended to be ran from a Network?

Which Operating System(s) is this aimed at?

Link to comment
Share on other sites

The TSProfiles directory hosts just the user profile directories, of which they are all just user names. So no random 'default user' or 'administrator' folders. All pair up to an actual end-user. The entry I highlighted would be the only entry in the .ini file as well as the only entry that needs comparison against the parent folder for that user's profile. All of this would run locally on the server hosting the TSProfiles directory, which is a Windows Server 2003 box.

Does TSProfiles contain only directories named with UserNames?

Is it likely that UserNames will be found elsewhere within the .ini file or that more than one UserName may appear in the same file?

Is the script being run locally/per machine or is this intended to be ran from a Network?

Which Operating System(s) is this aimed at?

Link to comment
Share on other sites

Here try this script it a Recursive script that looks for the ini

Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Col, Obj
'-> Script In Same Folder You Want To Recursive
Recursive(Fso.GetFolder("."))
'-> Path To Recursive Folder UnComment To Make Active
' Recursive(Fso.GetFolder("PLACE_PATH_TO_FOLDER"))

Function Recursive(Folder)
For Each Col In Folder.Files
If LCase(Right(Col.Name,3)) = "ini" Then
WScript.Echo Col.Path
End If
Next
For Each Obj In Folder.SubFolders
Recursive(Obj)
Next
End Function

Rename Recursive.vbs.txt to Recursive.vbs to make active

Recursive.vbs.txt

Link to comment
Share on other sites

Here's a 'batch' script I've thrown together possibly a little too quickly (I have been unable to test this as today I'm logged into a Linux Operating System):

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
(SET PD=D:\TSProfiles)
(SET PF=profile.ini)
IF /I "%CD%" NEQ "%PD%" (
SET "_=T"
2>NUL PUSHD %PD%||(
ECHO=Cannot find profile directory %PD%
>NUL PING -n 6 127.0.0.1
)
)
FOR /D %%# IN (*) DO CALL :SON %%#
IF DEFINED $ (
IF EXIST Badfile.txt (
DEL Badfile.txt
)
IF NOT EXIST _n$.txt (
REN _b$.txt Badfile.txt
) ELSE (
IF NOT EXIST _b$.txt (
REN _n$.txt Badfile.txt
) ELSE (
>NUL COPY _n$.txt + _b$.txt Badfile.txt
DEL _n$.txt _b$.txt
)
)
)
IF DEFINED _ POPD
GOTO :EOF

:SON
SET "UN=%*"
PUSHD %UN%
FOR /F "TOKENS=*" %%# IN ('2^>NUL DIR/B/S %PF%') DO (
SET "FP=%%#"
CALL SET "LP=%%FP:%PD%\=%%"
)
POPD
IF NOT DEFINED FP (
SET "$=T"
IF NOT EXIST _n$.txt (
>_n$.txt (
ECHO=No profile.ini found in the following directories:
ECHO=
)
)
>>_n$.txt ECHO= %UN%
) ELSE (
FIND /I "%UN%"<"%FP%">NUL 2>&1||(
SET "$=T"
IF NOT EXIST _b$.txt (
>_b$.txt (
ECHO=
ECHO=Profile mismatch found in the following files:
ECHO=
)
)
>>_b$.txt ECHO= %LP%
)
)
FOR %%# IN (UN FP LP) DO SET "%%#="

It looks a little long, but that's the price I paid for trying to have a neater looking output file.

Link to comment
Share on other sites

Here's a 'batch' script I've thrown together possibly a little too quickly (I have been unable to test this as today I'm logged into a Linux Operating System)

Yzöwl, that worked against a small test batch of users. I am going to make a full backup copy of our user profiles and run it against that to see what might fall out.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...