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

Moved start transcript within the script.

Fixed an issue where other logfiles got removed.
Added seconds to $currentDateTime.
parent 673e4a2f
Branches
No related tags found
No related merge requests found
...@@ -15,7 +15,7 @@ function Remove-OldLogFiles { ...@@ -15,7 +15,7 @@ function Remove-OldLogFiles {
[string]$scriptName [string]$scriptName
) )
# Get all log files for the current script # 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 # Check if the number of log files exceeds the maximum allowed
if ($logFiles.Count -gt $maxFiles) { if ($logFiles.Count -gt $maxFiles) {
...@@ -32,16 +32,11 @@ Write-Host "Starting script execution..." ...@@ -32,16 +32,11 @@ Write-Host "Starting script execution..."
<#== Get current date and time ==#> <#== Get current date and time ==#>
Write-Host "Getting 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 # Determine the name of the currently executing script without the extension
$scriptName = [System.IO.Path]::GetFileNameWithoutExtension($MyInvocation.MyCommand.Name) $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 # Define the busy.flag file path
$busyFlagPath = "C:\Install Logs\ChocolateyUpgrade_busy.flag" $busyFlagPath = "C:\Install Logs\ChocolateyUpgrade_busy.flag"
...@@ -51,6 +46,11 @@ if (Test-Path $busyFlagPath) { ...@@ -51,6 +46,11 @@ if (Test-Path $busyFlagPath) {
exit 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 # Create the busy.flag file and write start time and script information
$startTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss" $startTime = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$busyFlagContent = "Script: $scriptName`nStart Time: $startTime" $busyFlagContent = "Script: $scriptName`nStart Time: $startTime"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment