diff --git a/README.md b/README.md index 0055ff0..70fed0b 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,16 @@ You can run the `Winget-AutoUpdate-Install.ps1` script with parameters : **-Silent** Install Winget-AutoUpdate and prerequisites silently. +**-MaxLogFiles** +Specify number of allowed log files. +Default is 3 of 0-99: +Setting MaxLogFiles to 0 don't delete any old archived log files. +Setting it to 1 keeps the original one and just let it grow. + +**-MaxLogSize** +Specify the size of the log file in bytes before rotating. +Default is 1048576 = 1 MB + **-WingetUpdatePath** Specify Winget-AutoUpdate installation location. Default: `C:\ProgramData\Winget-AutoUpdate` (Recommended to leave default). diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 3559112..60876c0 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -10,6 +10,12 @@ https://github.com/Romanitho/Winget-AutoUpdate .PARAMETER Silent Install Winget-AutoUpdate and prerequisites silently +.PARAMETER MaxLogFiles +Specify number of allowed log files (Default is 3 of 0-99: Setting MaxLogFiles to 0 don't delete any old archived log files, 1 keeps the original one and just let it grow) + +.PARAMETER MaxLogSize +Specify the size of the log file in bytes before rotating. (Default is 1048576 = 1 MB) + .PARAMETER WingetUpdatePath Specify Winget-AutoUpdate installation localtion. Default: C:\ProgramData\Winget-AutoUpdate\ @@ -62,7 +68,7 @@ Install WAU with system and user context executions Configure WAU to bypass the Black/White list when run in user context .EXAMPLE -.\Winget-AutoUpdate-Install.ps1 -Silent -DoNotUpdate +.\Winget-AutoUpdate-Install.ps1 -Silent -DoNotUpdate -MaxLogFiles 4 -MaxLogSize 2097152 .EXAMPLE .\Winget-AutoUpdate-Install.ps1 -Silent -UseWhiteList @@ -100,7 +106,9 @@ param( [Parameter(Mandatory = $False)] [ValidateSet("Daily", "BiDaily", "Weekly", "BiWeekly", "Monthly", "Never")] [String] $UpdatesInterval = "Daily", [Parameter(Mandatory = $False)] [DateTime] $UpdatesAtTime = ("06am"), [Parameter(Mandatory = $False)] [Switch] $BypassListForUsers = $false, - [Parameter(Mandatory = $False)] [Switch] $InstallUserContext = $false + [Parameter(Mandatory = $False)] [Switch] $InstallUserContext = $false, + [Parameter(Mandatory = $False)] [ValidateRange(0,99)] [int32] $MaxLogFiles = 3, + [Parameter(Mandatory = $False)] [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB ) <# APP INFO #> @@ -337,6 +345,8 @@ function Install-WingetAutoUpdate { New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $NotificationLevel -Force | Out-Null New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force | Out-Null New-ItemProperty $regPath -Name WAU_PostUpdateActions -Value 0 -PropertyType DWord -Force | Out-Null + New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value $MaxLogFiles -PropertyType DWord -Force | Out-Null + New-ItemProperty $regPath -Name WAU_MaxLogSize -Value $MaxLogSize -PropertyType DWord -Force | Out-Null if ($DisableWAUAutoUpdate) { New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value 1 -Force | Out-Null } diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index 8c79824..e9eeb5d 100644 --- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -43,6 +43,16 @@ function Invoke-PostUpdateActions { Write-Log "-> Notification level setting was missing. Fixed with 'Full' option." } + #Set WAU_MaxLogFiles/WAU_MaxLogSize if not set + $MaxLogFiles = Get-ItemProperty $regPath -Name WAU_MaxLogFiles -ErrorAction SilentlyContinue + if (!$MaxLogFiles) { + New-ItemProperty $regPath -Name WAU_MaxLogFiles -Value 3 -PropertyType DWord -Force | Out-Null + New-ItemProperty $regPath -Name WAU_MaxLogSize -Value 1048576 -PropertyType DWord -Force | Out-Null + + #log + Write-Log "-> MaxLogFiles/MaxLogSize setting was missing. Fixed with 3/1048576 (in bytes, default is 1048576 = 1 MB)." + } + #Convert about.xml if exists (previous WAU versions) to reg $WAUAboutPath = "$WorkingDir\config\about.xml" if (test-path $WAUAboutPath) { diff --git a/Winget-AutoUpdate/functions/Start-Init.ps1 b/Winget-AutoUpdate/functions/Start-Init.ps1 index 5de8bfc..6ea3272 100644 --- a/Winget-AutoUpdate/functions/Start-Init.ps1 +++ b/Winget-AutoUpdate/functions/Start-Init.ps1 @@ -6,10 +6,22 @@ function Start-Init { [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 # Maximum number of log files to keep. Default is 3. Setting MaxLogFiles to 0 will keep all log files. - [int32] $MaxLogFiles = 3 + $MaxLogFiles = Get-ItemPropertyvalue -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate -Name "WAU_MaxLogFiles" -ErrorAction SilentlyContinue + if ($null = $MaxLogFiles) { + [int32] $MaxLogFiles = 3 + } + else { + [int32] $MaxLogFiles = $MaxLogFiles + } # Maximum size of log file. - [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB + $MaxLogSize = Get-ItemPropertyvalue -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate -Name "WAU_MaxLogSize" -ErrorAction SilentlyContinue + if (!$MaxLogSize) { + [int64] $MaxLogSize = 1048576 # in bytes, default is 1048576 = 1 MB + } + else { + [int64] $MaxLogSize = $MaxLogSize + } #Log Header $Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format (Get-culture).DateTimeFormat.ShortDatePattern)`n##################################################"