Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Update-Logs ($content) {
- $logPath = 'C:\S2S Logs'
- if (-not (Test-Path -Path $logPath)) {New-Item -Path $logPath -ItemType Directory}
- $date = Get-Date
- $lastMonth = $date.AddMonths(-1)
- $fileName = $date.ToString("yyyy-MM-dd") + "- S2S Log.txt"
- $filePath = ($logPath + "\" + $fileName)
- $exists = Test-Path $filePath
- if ($exists) {
- $string = (Get-Date).ToShortTimeString().ToString() + " $content"
- $string | Out-File -FilePath $filePath -Append
- }
- if (-not $exists) {
- $string | Out-File -FilePath $filePath
- }
- # Clean Up Logs Older than 1 month
- $items = Get-ChildItem -Path $logPath -Recurse -Filter *.txt | Where-Object {$_.CreationTime.Date -lt $lastMonth}
- $items | Remove-Item -Force
- }
Add Comment
Please, Sign In to add comment