Created
April 24, 2017 07:27
-
-
Save ruxo/6d8581111517ecb92f346c52aeb75ebe to your computer and use it in GitHub Desktop.
Powershell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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