I recently got the question to find all Symantec BESR snaphot files older than 2 weeks (the retention period) on the company servers. This so that we could clear up some space on the snapshot volumes.
I decided to make a general purpose script of it.
You can use it to find old logfiles, etc.
What the script does:
- create an array with all server you want to check (replace srv001, etc with your server names)
- create a variable with a date of 2 weeks ago (Date -14)(can easily be changed in 30, 60 days ago)
- change the variable date to the UTC date of 14 days ago (because WMI works with UTC dates)
- for each server in the array
- make a wmi connection
- query for files with specific extensions and a creation date older than 14 days ago
- in this example i took .txt and .csv extensions, change them in whatever filetype you want
The script is tested in an win2003 environment.
Follow the next steps to run the script (admin rights needed):
- copy and paste the script in your favorite text editor
- replace the strings ‘srv001′ and ‘srv002′ with the name of your exchange server
- replace the extensions ‘txt’ and ‘csv with the extensions you need
- save the script (for example c:tempfindoldfileswithspecificextensions.vbs)(or something shorter..)
- open a command prompt
- go to “c:temp”
- give “cscript findoldfileswithspecificextensions.vbs” (without quotes) and enter
When you want the output in a file please give this command:
“cscript findoldfileswithspecificextensions.vbs > findoldfileswithspecificextensions.txt” (again without the quotes)
The script:
' Name : findoldfileswithspecificextensions.vbs
' Description : VBscript to find files with specific extensions and creation date on remote servers
' Author : dirk adamsky - deludi bv
' Version : 1.00
' Date : 21-03-2011
' Level: intermediate
arrServers = Array("srv001","srv002")
strDate = Date - 14
Set objDateToUtcDate = CreateObject("WbemScripting.SWbemDateTime")
objDateToUtcDate.SetVarDate(strDate)
For Each Server in arrServers
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\" & Server & "rootcimv2")
Set colFiles = objWMIService.ExecQuery("Select * from CIM_DataFile where (Extension = 'txt' or Extension = 'csv') and CreationDate < '" & objDateToUtcDate & "'")
For Each objFile in colFiles
Wscript.Echo objFile.Name
Next
Set colFiles = Nothing
Set objWMIService = Nothing
Next
Set objDateToUtcDate = Nothing
When you have problems/questions please post a reply or give a ‘star’ rating.
Happy scripting.
Best regards,
Dirk Adamsky – Deludi BV
