Create bat file to run mstsc/delete files over 200 days old?

March 25, 2012 at 21:47:01
Specs: Vista 64 bit sp2, 4gb RAM
Hi, I need to create a batch file that will open an mstsc session to a live service box (running Win2008) then automatically delete any files contained within a mail attachment archive that are over 200 days old? The goal is simple automation, but needs to be controlled / triggered from a support PC located off-site from the host's data centre.

The job would need be run on demand but only when our support team were to receive a change request from the end user. Therefore i've disregarded the idea of creating a scheduled task on the host. Also, the end users would not be happy with the batch or task file being kept on their server??

I'm sorry for so much background info, i'm just a tad lost with the best way to go with this.

See More: Create bat file to run mstsc/delete files over 200 days old?

Report •

March 26, 2012 at 08:09:56
Something like this should work. Hostnames.txt should contain the hostnames for each box this needs to be ran on.


@echo off
for /f "tokens=* delims=" %%i in (
'type hostnames.txt'
) do (
psexec \\%%i forfiles *.* /p c:\your\directory /d -200 /c "cmd /c echo del @file >nul"

This will delete all files from c:\your\directory, that are 200 days old, or more. If you need recursion you can add the /s switch to the forfiles command. Once you verify it is working properly, remove the echo.


Report •

March 26, 2012 at 11:59:33
Thank you Tony, i'll give this a bash and report back to you.

Report •

March 26, 2012 at 14:42:08
Note: You'll need to download PsExec.

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question