Delete folder script

Job ID: 33687531

Budget: $10 – $30 USD

I am looking for an a script (cant find one exactly on the web) that will delete a folder and all its contents based on creation date. For example, I have a folder containing 30 or more folders of log files, 1 for each day of the month.

I would like to keep the last 2 folders from the current date, then delete all folders / subfolders that are older than that so in the example below the 8th and 9th would be gone and the rest remain.

<DIR> 20220508
<DIR> 20220509
<DIR> 20220510
<DIR> 20220511
<DIR> 20220512

I want to reassert. Lots of scripts out there. Not all bullet proof. Looking for something that works consistently so i don't have to manually delete these folders to keep the size of the drive low.
Related categories: Software Architecture DOS Powershell VBScript