How to automate remote search of files?


On the occasion of the spring system administrators complain that the weekly Bacup all servers takes more than a day and asked to clean bakapy. We have more than 20 sql servers, and therefore uninteresting to look manually.

The problem is this:
— find *.bak files are "large" size, which was not updated more than a month
— find instalasi (*.exe, *.zip, etc) large size
find detached database file (mdf / ndf / ldf)

The solution chosen WMI

select * from CIM_DataFile where extension='bak' works
with acceptable speed

but the search
select * from CIM_DataFile where name like '%.bak' and FileSize > 1000000
select * from CIM_DataFile where FileSize > 100000000
select * from CIM_DataFile

work "endlessly"

the server is not loaded 100%, of visible download processes antivirus.

A Google search led to the article
in which write that the search through the WMI 80,000 files in 6 times more slowly, but it is in Windows 2000.

Environment we have Windows 2003 — 2008 R2.

How to speed up the search and what options still there?

Thank you
October 8th 19 at 00:38
3 answers
October 8th 19 at 00:40
I think your ideology needs a little change, in my opinion dostatochnym will focus on the creation date of the file and its extension. If you have MSSQL, I don't see the problem, set the file cleanup, per day, onin of the standard routine transactions MSSQL. Solution for finding files by date, is in Google.
October 8th 19 at 00:42
I think a simple script to iterate over the files with instant removal for you.
October 8th 19 at 00:44
What options still there?

  1. LogParser. The syntax is roughly the same SQL-tion, is a big plus, allows you to specify the tricky conditions and to generate reports. About performance — I am sure that will be faster. As far as I remember, it works not through WMI, and directly with WinAPI. Remember, the search for all recently modified files on the C: drive (home system) occupy no more than a couple of minutes.
  2. The Command ForFiles. In 2008, there are normally, in 2003 you can copy. The performance of the actual search, I think, not very different from the dir /s. Another thing is that to perform an action on each selected file creates a new process, it may slow down.
  3. PowerShell. About the performance do not say anything, no experience. But I think that everything is in order (if not using WMI to work).
  4. Finally, banal dir c treatment result in the batch file or in js.

Find more questions by tags Database administrationSystem administration