Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
snippets
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Andreas Lindemark
snippets
Commits
673e4a2f
Commit
673e4a2f
authored
2 months ago
by
Andreas Lindemark
Browse files
Options
Downloads
Patches
Plain Diff
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
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Windows/Chocolatey/ChocolateyUpgrade.ps1
+17
-18
17 additions, 18 deletions
Windows/Chocolatey/ChocolateyUpgrade.ps1
with
17 additions
and
18 deletions
Windows/Chocolatey/ChocolateyUpgrade.ps1
+
17
−
18
View file @
673e4a2f
...
...
@@ -12,10 +12,10 @@ function Remove-OldLogFiles {
param
(
[
string
]
$logPath
,
[
int
]
$maxFiles
,
[
string
]
$scriptName
WithoutExtension
[
string
]
$scriptName
)
# Get all log files for the current script
$logFiles
=
Get-ChildItem
-Path
$logPath
-Filter
"
$scriptName
WithoutExtension
_
*.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
`n
Start 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
-scriptName
WithoutExtension
$scriptNameWithoutExtension
Remove-OldLogFiles
-logPath
"C:\Install Logs"
-maxFiles
45
-scriptName
$scriptName
<#== Stop Transcript ==#>
Write-Host
"Stopping transcript..."
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment