Greetings,
I am just staring my PowerShell Career and would like assistance in creating my first script. I have various programs (on various servers) that write text logs which use up a lot of disk space. The problem I have is that the only item in common is that all the logs us a date format. Some have text before and after the date. Example: Applog-yyyy-mm-dd.txt or [log.mm.dd.yyyy.xx.txt], or svc-yyyy-mm-ddlog.txt
I need to assistance in creating a script that will locate all .txt files with a date older than 30 days in the name and delete it.
Below is a start to the script however, I am unable to figure out how to add the "Date" in the name and filter by "Less Than" x date.
$date = (get-date).AddDays(-31).ToString("yyyy-MM-d")
Get-ChildItemC:\Test1\*.txt|Where {$_.Name -match"\d\-"} | Remove-Item -Confirm:$False -Recurse:$true