Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Re: PS Script to automate checking date of file and delete if old

Reply
 
Old 07-09-2008   #1 (permalink)
Shay Levy [MVP]


 
 

Re: PS Script to automate checking date of file and delete if old

Hi cmoore01,

This will delete the files

dir \\server\scans\everyone -filter *.pdf | where { ((get-date)-$_.creationTime).days
-le 14 } | remove-item -force -whatIf


The -whatIf parameter tells you what would happen if you exceute the command,
so remove it when you're ready to schedule the job (otherwise nothing will
be deleted).


To schedule it, create a new schedule job:

1. Save the command in a PowerShell script file (e.g. C:\scripts\deleteScans.ps1)
2. In the schedule job 'Task tab' > Run, type: C:\WINDOWS\system32\WindowsPowerShell\v1.0\PowerShell.exe
C:\scripts\deleteScans.ps1
In the 'Start In' type: C:\scripts


Now test it, right click the new job and click 'Run'.


---
Shay Levy
Windows PowerShell MVP
blog: http://blogs.microsoft.co.il/blogs/ScriptFanatic



c> New to PS and scripting. Two questions/needs: Need an example of a
c> script that will check a specific direcotry on a server, check the
c> date created of specific type of file extension and delete all files
c> older than a specified time. Specifics: S:\Everyone\*.pdf,
c> (\\server\scans\everyone\*.pdf) and files are older than 14 days.
c>
c> Second part of this post, is how do I schedule this as a task to run
c> on the server?
c>
c> much appreciated...thanks...
c>



My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
automate a login script to vpn / remote desktop Network & Sharing
powershell script help - recursive delete based on modified date PowerShell
Re: Help required with file size checking script VB Script
Sample script to delete lines from a file based on a string PowerShell
Send-FTP Script with Error Checking? PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46