![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||