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.

  |  
Create Test Log Files
# Set number of days, in the past, to create log files for
$days = 14
# Set directory to create logs in
$directory = "C:\Test\Logs"

$i=1
While($i -lt $days){
    # Get Date and create log file
    $date = (Get-Date).AddDays(-$i)
    $logFile = "u_ex" + ($date.Year).ToString().Substring(2,2) + (($date.Month).ToString().PadLeft(2)).Replace(" ","0") + (($date.Day).ToString().PadLeft(2)).Replace(" ","0") + ".log"
    $logPath = join-path $directory $logFile
    $date | out-file $logPath

    # Set the Creation, Write, and Access time of log file to match date
    Get-Item $logPath | % { $_.CreationTime = $date; $_.LastWriteTime = $date; $_.LastAccessTime = $date }

    $i++
}
Details
These commands will create a log file for each day, go back as many days as specified. The file attributes will be set to the past as well. This is great for testing cleanup scripts.

  |