Delete Files Older Than Specified Number of Days

# Set number of days, in the past, to delete files
$days = 7
# Set directory to create logs in
$directory = "C:\Test\Logs"

# Get all files in the directory include '-recurse' to also get sub folders
$files = Get-ChildItem -Path $directory -File
# filter to ones last written to over X number of days
$ToDelete = $files | Where-Object{$_.LastWriteTime -lt (Get-Date).Date.AddDays(-$days)}
# Delete the files
$ToDelete | Remove-Item -Force
Details
These commands return all the files in a directory and remove the ones older than the specified number of days.