-1

I have an interesting problem. I need to delete directories that are older than x days but are only numerical. We have a log folder that has log files that we need to delete but other files and folders are also stored in the same locatin.. Normally i would do PS scripts to delete all directories over x amount of days but i can delete all folders. I only need to delete folders that are fully numeric.

Wanted to see if anyone had any ideas?

michael B
  • 1
  • 1

1 Answers1

0

$root = 'C:\logs'

Get-ChildItem -Path $root | Where-Object { $.name -match "^\d*$" -and $.LastWriteTime -lt (Get-Date).Adddays(-45) } | Remove-Item -Recurse -Force

michael B
  • 1
  • 1