Guest User

Untitled

a guest
Dec 18th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. function Update-Logs ($content) {
  2. $logPath = 'C:\S2S Logs'
  3. if (-not (Test-Path -Path $logPath)) {New-Item -Path $logPath -ItemType Directory}
  4. $date = Get-Date
  5. $lastMonth = $date.AddMonths(-1)
  6. $fileName = $date.ToString("yyyy-MM-dd") + "- S2S Log.txt"
  7. $filePath = ($logPath + "\" + $fileName)
  8. $exists = Test-Path $filePath
  9. if ($exists) {
  10. $string = (Get-Date).ToShortTimeString().ToString() + " $content"
  11. $string | Out-File -FilePath $filePath -Append
  12. }
  13. if (-not $exists) {
  14. $string | Out-File -FilePath $filePath
  15. }
  16. # Clean Up Logs Older than 1 month
  17. $items = Get-ChildItem -Path $logPath -Recurse -Filter *.txt | Where-Object {$_.CreationTime.Date -lt $lastMonth}
  18. $items | Remove-Item -Force
  19. }
Add Comment
Please, Sign In to add comment