.vbs Script to find last modified date of latest files in folder

Posted on 2010-04-07
Medium Priority
Last Modified: 2013-11-22
Hi Guys,

Due to the limitation of sophos on netware we are left not with no report for last AV update at a central location. So we have to go and manually check the status on every server.

So I started to create a batch script to run and verify all the files for the last modified date in a folder on the server which would tell me if the definitions are up to date. Doing this script in batch was limited. So need help creating script in .vbs

Can anyone help create a script which will:
1 - Go check the file modified date in many folders and return the output to a excel or a txt file with the following messages:
"Completed" if the modified date of any file is NOT older than 6 hours.
"Failed" if the modified date of any file is older than 6 hours.

2- The script would have to exclude the .cfg and .log file types from be checked for last modified date.

3-  The script would need a loop and run on many servers which can be listed in a variable at the top of the script. Also amend the output file with the status of every server after a loop.

The folder location on each netware server would be:

Thanks Guys
Question by:harps21k
  • 2
  • 2
LVL 14

Expert Comment

ID: 30063073
Just to clarify - you want to check the times of all files with the exception of .log and .cfg files that are located in a number of folders.  If even one of the files within any of the folders is older than 6 hours report a failure otherwise the machine is up to date?

Author Comment

ID: 30088290
Yeh I would like it to check for everything except the .cfg and .log file.

Basically I need it to query for anyone of the most recent updated file and report as failed if that file has been modified older than 6hours.  Also report as completed if the most recent updated file is newer than 6hours.

I don't know which file would be updated that why I need it to query for anyone of the files to find at least 1 recent modified file to report the update status. Also have the exclusion mentioned above.

LVL 31

Accepted Solution

merowinger earned 2000 total points
ID: 30107945
This should do it. I've only a restricted testing environemt, but for what i saw it should work
set objFSO = CreateObject("Scripting.FileSystemObject")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & "." & "\root\cimv2")
Set objPCs = objFSO.OpenTextFile("D:\Computers.txt")
Set objOutput = objFSO.CreateTextFile("D:\Output.log")
bolFilesOlder = False
strFolder = "sys\sweep"

Do While Not objPCs.AtEndOfStream
	strCurrentPC = objPCs.ReadLine
	'First check connection to the PC
	Set colPing = objWMIService.ExecQuery("Select * from Win32_PingStatus Where Address = '" &strCurrentPC &"'")
	For Each objPing In colPing
		If objPing.StatusCode = 0 Then
			Call CheckFiles ("\\" &strCurrentPC &"\" &strFolder)
			If bolFilesOlder = True Then
				objOutput.WriteLine strCurrentPC &" - Failed"
				objOutput.WriteLine strCurrentPC &" - Completed"
			End If
			bolFilesOlder = False
			objOutput.WriteLine strCurrentPC &" is not online"
		End If

Sub CheckFiles(Folder)
WScript.Echo Folder
Set curFolder = objFSO.GetFolder(Folder)
For Each file in curFolder.Files
	If UCASE(Right(file,3)) <> "LOG" And UCASE(Right(file,3)) <> "CFG" Then
		strDateModified = objFSO.GetFile(file).DateLastModified
		If DateAdd("h",6,strDateModified) < Now Then bolFilesOlder = True
	End If

For Each subfolder In curFolder.SubFolders

End Sub

Open in new window


Author Comment

ID: 32695394
LVL 31

Expert Comment

ID: 32789560
Any update?

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
If you thought ransomware was bad, think again! Doxware has the potential to be even more damaging.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

607 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question