Skip to content

Instantly share code, notes, and snippets.

@ruxo
Created April 24, 2017 07:27
Show Gist options
  • Select an option

  • Save ruxo/6d8581111517ecb92f346c52aeb75ebe to your computer and use it in GitHub Desktop.

Select an option

Save ruxo/6d8581111517ecb92f346c52aeb75ebe to your computer and use it in GitHub Desktop.
Powershell
cd W3SVC1
$now = Get-Date
$today = $now.Date
$date_groups = Get-ChildItem *.log | where { $_.Length -gt 0 -and $_.LastWriteTime.Date -lt $today } | group { $_.LastWriteTime.Date }
cd ..
foreach($g in $date_groups){
$date = $g.Values[0]
$name = "iis_logs-$($date.Year)$($date.Month.ToString("D2"))$($date.Day.ToString("D2"))"
$files = $g.Group
$cmd = "7z a -t7z -mx=9 -mmt=4 -sdel $($name) $($files)"
"Backup $($name)"
iex $cmd
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment