Delete older files using Powershell?

One of thing I like linux (unix) is the scripting. The one I like most is to remove files older than 10 days:

find /yourpath/yourfiles* -type f -mtime +10 -exec rm '{}' \;

But I  need to do this in Windows Powershell, and how? Here is the answer:

$Now=get-date

$LastWrite = $Now.AddDays(-10)

Get-ChildItem \yourpath\yourfile* |Where {$_.LastWriteTime -le "$LastWrite"}|remove-item -recurse

About henry416
I am a computer technology explorer and an university student based on Toronto. If you have any question, please feel free to discuss and comment here

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s