Put log in user profile if run with user context

pull/3/head
Romain 2022-02-19 16:08:39 +01:00
parent 2d4ed7c565
commit d5a8ad2873
1 changed files with 19 additions and 10 deletions

View File

@ -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