From d5a8ad28739ecab193d8456f987900b8c4e1abfd Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Sat, 19 Feb 2022 16:08:39 +0100 Subject: [PATCH] Put log in user profile if run with user context --- Winget-AutoUpdate/winget-upgrade.ps1 | 29 ++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/Winget-AutoUpdate/winget-upgrade.ps1 b/Winget-AutoUpdate/winget-upgrade.ps1 index d62b191..d6e991d 100644 --- a/Winget-AutoUpdate/winget-upgrade.ps1 +++ b/Winget-AutoUpdate/winget-upgrade.ps1 @@ -4,19 +4,28 @@ function Init { #Var $Script:WorkingDir = $PSScriptRoot - #Logs initialisation - $LogPath = "$WorkingDir\logs" - if (!(Test-Path $LogPath)){ - New-Item -ItemType Directory -Force -Path $LogPath - } - - #Log file - $Script:LogFile = "$LogPath\updates.log" - #Log Header $Log = "##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format 'dd/MM/yyyy')`n##################################################" $Log | Write-host - $Log | out-file -filepath $LogFile -Append + try{ + #Logs initialisation + $LogPath = "$WorkingDir\logs" + if (!(Test-Path $LogPath)){ + New-Item -ItemType Directory -Force -Path $LogPath + } + #Log file + $Script:LogFile = "$LogPath\updates.log" + $Log | out-file -filepath $LogFile -Append + } + catch{ + #Logs initialisation + $LogPath = "$env:USERPROFILE\Winget-AutoUpdate\logs" + if (!(Test-Path $LogPath)){ + New-Item -ItemType Directory -Force -Path $LogPath + } + $Script:LogFile = "$LogPath\updates.log" + $Log | out-file -filepath $LogFile -Append + } #Get locale file for Notification #Default en-US