From e7bf4355ab597b4b48a797f3debcd6e5e015f007 Mon Sep 17 00:00:00 2001 From: dreamforceinc Date: Wed, 3 Apr 2024 16:07:16 +0300 Subject: [PATCH] Update wDayzLogRotation.ps1 Added some parameters check. --- wDayzLogRotation.ps1 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/wDayzLogRotation.ps1 b/wDayzLogRotation.ps1 index b48f44a..2cc55ab 100644 --- a/wDayzLogRotation.ps1 +++ b/wDayzLogRotation.ps1 @@ -1,11 +1,11 @@ -# wDayzLogRotation 0.5 +# wDayzLogRotation 0.6 # Input parameters: # # (Usually inside the server's root folder) # [Path to BEC location] (Optional. By default, BEC location inside the server's root folder) # # Example: -# powershell.exe -File "wDayzLogRotation.ps1" "Z:\Servers\DayZServer" "Instance_1" "Z:\BEC" +# powershell.exe -File "wDayzLogRotation.ps1" "Z:\Servers\DayZServer" "Instance_1" "D:\server tools\BEC" # $date = Get-Date # Get current system date $daysAmount = 7 # Number of days to store logs @@ -18,7 +18,17 @@ if (!$serverLocation) { $serverLocation = "Z:\DayZServer" } if (!$instance) { $instance = "Instance" } if (!$becLocation) { $becLocation = "${serverLocation}\BEC" } -$instanceDir = "${serverLocation}\${instance}" +if ([System.IO.Path]::IsPathRooted($instance)) { + $instanceDir = "${instance}" + $instance = Split-Path -Path "${instanceDir}" -Leaf +} else { + $instanceDir = "${serverLocation}\${instance}" +} + +if (![System.IO.Path]::IsPathRooted($becLocation)) { + $becLocation = "${serverLocation}\${becLocation}" +} + $destDir = "${instanceDir}\RotatedLogs" $destDelDir = $destDir $daysAmount = [Math]::Abs($daysAmount) @@ -33,7 +43,6 @@ Write-Host "Start Log rotation powershell script" # Write-Host " instanceDir: '${instanceDir}'" # Write-Host " destDir: '${destDir}'" # Write-Host " destDelDir: '${destDelDir}'" -# Write-Host " daysAmount: '${daysAmount}'" # Write-Host " becLocation: '${becLocation}'" # Write-Host " becLogDir: '${becLogDir}'" # Write-Host " becDestDir: '${becDestDir}'"