Ex.1:
get-childitem c:\inetpub\logs\LogFiles -recurse | where {$_.lastwritetime -lt (get-date).adddays(-30) -and -not $_.psiscontainer} |% {remove-item $_.fullname -force -verbose}
Ex.2:
# Number of days to retain logfiles
$days = 14
# Location of the MTAs log files
$basepath = "E:\MA\logs"
#Location to copy logs for processing
$dstpath = "\\loggingds\MTA_Logs"
# Filetypes to copy
$filetypes = ("Queued", "Processed", "Deferred")
# Shouldn't need to change anything below here
#--------------------------------------------------------------------
$fileprefix = (Get-Date).AddDays(-1) | Get-Date -Format yyyyMMdd
$accounts = Get-ChildItem $basepath
#loop through the folders in the accounts directory
foreach($account in $accounts) {
$account