Powershell – Howto remove files and folder that is older than X days

Hello script geeks!

Today I want to talk about how you can easiest remove files and folder that is older than X days. You can get use of cmdlet Get-ChildItem to List all files and folder, where CreationDate i older than X days. And to remove the items get use of cmdlet Remove-Item.

Run following cmdlet:

$FilePath = "<-Path-> Ex: c:\test\" # Set Folder to check files and folder
$FileThatIsOlderThanDays = -7 # Set number of days back in time you will go

Get-ChildItem -Path ($FilePath) -Recurse | Where-Object {$_.CreationDate -le (Get-Date).AddDays($FileThatIsOlderThanDays)} | Remove-Item -Force

 

Lämna ett svar

E-postadressen publiceras inte. Obligatoriska fält är märkta *

Powershell GUI SCCM Client Tools

SCCM Client Tools (right now it´s Beta) is Microsoft Powershell tool, the GUI is created with SAPIEN Powershell Studio. Import Computers from SCCM collection and initiate client tasks. Requirements: 1)

Tool – Application Folder Builder 1.0.0.1

I Made a tool again. This time I meet a problem in Application Packaging Project. Where we wanted to collect our applications we packed in one sorted folder place. So

Howto – Connect to Configuration Manager 2012 from Powershell

Hi, Emil here. Have you ever wonder howto connect to a configuration manager 2012 site from Powershell? Okay, follow the steps below to success: Requirements: SCCM 2012 Console Powershell 3.0