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 *

Prompt for Computer Name during OSD in Task Sequence with Powershell GUI

1) Download the Script. Change the file extension from txt to ps1 and save it to networkshare. The GUI is created with Sapien Powershell Studio 2) Create a package in

Powershell – Automating Computer naming during OSD

1) Save the following script as OSDComputerName.ps1 on a networkshare. I use Hyper-v in my labb and Hyper-v virtual machin gives you over 30 digits of serialnumber and here in

Howto Force remote clients to update their Sccm clients Machine Policy Retrieval & Evaluation Cycle via Powershell

Hello! Here is some script to force a Sccm Client’s Machine Policy Cycle on remote client in a domain. But first. You need to be sure you have enable the