I found Yes.
With this code:
#-----------------------------------------------
#-------------------- INFOS --------------------
#Script: StorjLogsRotation
#Version: 1.0.1.2
#Date: 27/04/2020
#Author: JDA
#------------------- Variables ------------------
$PathLogLive = 'C:\Program Files\Storj\Storage Node\'
$PathLogArchive = 'F:\logs_auto_clean\'
$DateTimeFormat = "yyyy-MM-dd HH'h'mm"
$RententionInDays = 88888
#-----------------------------------------------
Function StorjLogsRotation{
ForEach($L in (Get-ChildItem -LiteralPath $PathLogLive -Filter '*.log' -Recurse:$False)){
RotateLog -Source $L.FullName -DestinationPath $PathLogArchive -RententionInDays $RententionInDays
}
}
Function RotateLog([String]$Source, [String]$DestinationPath,[Int]$RententionInDays){
$Format = '{0}_[{1}]{2}'
If(Test-Path -LiteralPath $Source){
$S = Get-Item -LiteralPath $Source
$Destination = Join-Path -Path $DestinationPath -ChildPath ($Format -F $S.BaseName, ((Get-Date).ToString($DateTimeFormat)), $S.Extension)
If(!(Test-Path -LiteralPath $DestinationPath)){$Null = New-Item -Path $DestinationPath -Type Directory -Force}
Copy-Item -Path $Source -Destination $Destination -Force
Clear-Content -LiteralPath $Source -Force
Get-ChildItem -LiteralPath $DestinationPath -File -Filter ($Format -F $S.BaseName, '*',$S.Extension) | ? LastWriteTime -le ((Get-Date).AddDays(-$RententionInDays)) | Remove-Item -ErrorAction SilentlyContinue
}
}
StorjLogsRotation
but i had to help my self with autoit .au3 file, and compile to .exe with this 2nd code:
#include <AutoItConstants.au3>
#include <MsgBoxConstants.au3>
#include <Array.au3>
#RequireAdmin
;$CmdPid = Run("C:\Users\urmom\Desktop\logrotate.ps1
sleep(3000)
;Powershell.exe -File C:\Users\urmom\Desktop\logrotate.ps1
;powershell.exe -executionpolicy bypass -File C:\Users\urmom\Desktop\logrotate.ps1
;powershell.exe -noexit "& 'C:\Users\urmom\Desktop\logrotate.ps1'"
Local $iPid = Run("powershell.exe -executionpolicy bypass -windowstyle hidden -noninteractive -nologo -file C:\Users\" & @UserName & "\Desktop\logrotate.ps1", "c:\", @SW_HIDE, $STDOUT_CHILD)
processWaitClose($iPid)
Local $sOutput = StdoutRead($iPid)
because somehow it was the fastest way to solve it for me.
Probably can be made simpler, but it was working so yeah.
Obviously You have to update that with Your OWN user name and C:\ file paths!
So basically You Task Schedule the program of 2nd_code_theAutoit.exe
which kick starts the 1st code, made by JDA, and saved in .ps1 file.
I discovered it won’t interrupt the storagenode windows GUI,
and the logs are cleaned as often as You want,
i set it daily in Task Scheduler, like every 2 days lately, makes me a 350-500MB files,
on other busy node 1,2-2,5GB files every 2 days.