From 2eae83d74d63c26d1d146028362738ec88e0c69b Mon Sep 17 00:00:00 2001 From: Andreas Lindemark <andreas.lindemark@liu.se> Date: Mon, 10 Mar 2025 19:02:29 +0100 Subject: [PATCH] Moved start transcript within the script. Fixed an issue where other logfiles got removed. Added seconds to $currentDateTime. --- Windows/Chocolatey/ChocolateyUpgrade.ps1 | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Windows/Chocolatey/ChocolateyUpgrade.ps1 b/Windows/Chocolatey/ChocolateyUpgrade.ps1 index a460815..c46f555 100644 --- a/Windows/Chocolatey/ChocolateyUpgrade.ps1 +++ b/Windows/Chocolatey/ChocolateyUpgrade.ps1 @@ -15,7 +15,7 @@ function Remove-OldLogFiles { [string]$scriptName ) # Get all log files for the current script - $logFiles = Get-ChildItem -Path $logPath -Filter "$scriptName_*.log" | Sort-Object LastWriteTime -Descending + $logFiles = Get-ChildItem -Path $logPath -Filter "$scriptName`_*.log" | Sort-Object LastWriteTime -Descending # Check if the number of log files exceeds the maximum allowed if ($logFiles.Count -gt $maxFiles) { @@ -32,16 +32,11 @@ Write-Host "Starting script execution..." <#== Get current date and time ==#> Write-Host "Getting current date and time..." -$currentDateTime = Get-Date -Format "yyyy-MM-dd_HHmm" +$currentDateTime = Get-Date -Format "yyyy-MM-dd_HHmmss" # Determine the name of the currently executing script without the extension $scriptName = [System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name) -<#== Start Transcript ==#> -Write-Host "Starting transcript..." -$transcriptPath = "C:\Install Logs\$scriptName`_$currentDateTime.log" -Start-Transcript -Path $transcriptPath - # Define the busy.flag file path $busyFlagPath = "C:\Install Logs\ChocolateyUpgrade_busy.flag" @@ -51,6 +46,11 @@ if (Test-Path $busyFlagPath) { exit } +<#== Start Transcript ==#> +Write-Host "Starting transcript..." +$transcriptPath = "C:\Install Logs\$scriptName`_$currentDateTime.log" +Start-Transcript -Path $transcriptPath + # Create the busy.flag file and write start time and script information $startTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $busyFlagContent = "Script: $scriptName`nStart Time: $startTime" -- GitLab