Skip to content
Snippets Groups Projects
Commit 673e4a2f authored by Andreas Lindemark's avatar Andreas Lindemark
Browse files

Modified some variables, fixed issue with transcript path and busy.flag

parent d031757e
No related branches found
No related tags found
No related merge requests found
......@@ -12,10 +12,10 @@ function Remove-OldLogFiles {
param (
[string]$logPath,
[int]$maxFiles,
[string]$scriptNameWithoutExtension
[string]$scriptName
)
# Get all log files for the current script
$logFiles = Get-ChildItem -Path $logPath -Filter "$scriptNameWithoutExtension_*.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) {
......@@ -30,6 +30,18 @@ function Remove-OldLogFiles {
<#== Script starts here ==#>
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"
# 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"
......@@ -41,22 +53,9 @@ if (Test-Path $busyFlagPath) {
# Create the busy.flag file and write start time and script information
$startTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$scriptName = $MyInvocation.MyCommand.Name
$busyFlagContent = "Script: $scriptName`nStart Time: $startTime"
New-Item -Path $busyFlagPath -ItemType File -Force > null
Set-Content -Path $busyFlagPath -Value $busyFlagContent > null
<#== Get current date and time ==#>
Write-Host "Getting current date and time..."
$currentDateTime = Get-Date -Format "yyyy-MM-dd_HHmm"
# Determine the name of the currently executing script without the extension
$scriptNameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name)
<#== Start Transcript ==#>
Write-Host "Starting transcript..."
$transcriptPath = "C:\Install Logs\$scriptNameWithoutExtension_$currentDateTime.log"
Start-Transcript -Path $transcriptPath
New-Item -Path $busyFlagPath -ItemType File -Force > $null
Set-Content -Path $busyFlagPath -Value $busyFlagContent > $null
<#== Apply random delay if enabled ==#>
if ($EnableRandomDelay) {
......@@ -73,7 +72,7 @@ Write-Host "Chocolatey upgrade completed."
<#== Remove old log files ==#>
Write-Host "Removing old log files..."
Remove-OldLogFiles -logPath "C:\Install Logs" -maxFiles 45 -scriptNameWithoutExtension $scriptNameWithoutExtension
Remove-OldLogFiles -logPath "C:\Install Logs" -maxFiles 45 -scriptName $scriptName
<#== Stop Transcript ==#>
Write-Host "Stopping transcript..."
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment