From 1fd3fe060aca551052f29462c360913e373ce445 Mon Sep 17 00:00:00 2001 From: KnifMelti Date: Sat, 18 May 2024 23:45:56 +0200 Subject: [PATCH] SymLink Fix --- .../WAU/Winget-AutoUpdate/Winget-Upgrade.ps1 | 18 +++++++++++------- .../functions/Invoke-PostUpdateActions.ps1 | 12 ------------ 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/Sources/WAU/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Sources/WAU/Winget-AutoUpdate/Winget-Upgrade.ps1 index d4958e5..1c5b124 100644 --- a/Sources/WAU/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Sources/WAU/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -22,6 +22,17 @@ $Script:SessionID = [System.Diagnostics.Process]::GetCurrentProcess().SessionId #Check if running as system if ($IsSystem) { + # Check if Intune Management Extension Logs folder exists + if ((Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs" -ErrorAction SilentlyContinue)) { + # Check if updates.log and symlink WAU-updates.log exists, make symlink (doesn't work under ServiceUI) + if ((Test-Path -Path ('{0}\logs\updates.log' -f $WorkingDir) -ErrorAction SilentlyContinue) -and !(Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log" -ErrorAction SilentlyContinue)) { + $null = New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log" -ItemType SymbolicLink -Value $LogFile -Force -ErrorAction SilentlyContinue + } + # Check if install.log and symlink WAU-install.log exists, make symlink (doesn't work under ServiceUI) + if ((Test-Path -Path ('{0}\logs\install.log' -f $WorkingDir) -ErrorAction SilentlyContinue) -and !(Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ErrorAction SilentlyContinue)) { + $null = (New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ItemType SymbolicLink -Value ('{0}\logs\install.log' -f $WorkingDir) -Force -Confirm:$False -ErrorAction SilentlyContinue) + } + } #Check if running with session ID 0 if ($SessionID -eq 0) { #Check if ServiceUI exists @@ -346,13 +357,6 @@ if (Test-Network) { #Check if user context is activated during system run if ($IsSystem) { - #Adds SymLink if Intune managed - $IntuneLogPath = "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs" - if ((Test-Path "$IntuneLogPath") -and !(Test-Path "$IntuneLogPath\WAU-updates.log")) { - Write-ToLog "Creating SymLink for log file (WAU-updates) in Intune Management Extension log folder" "Yellow" - New-Item -Path "$IntuneLogPath\WAU-updates.log" -ItemType SymbolicLink -Value $LogFile -Force -ErrorAction SilentlyContinue | Out-Null - } - #Run WAU in user context if feature is activated if ($WAUConfig.WAU_UserContext -eq 1) { diff --git a/Sources/WAU/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Sources/WAU/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index a04621f..fa3db58 100644 --- a/Sources/WAU/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Sources/WAU/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -5,18 +5,6 @@ function Invoke-PostUpdateActions { #log Write-ToLog "Running Post Update actions:" "yellow" - # Check if Intune Management Extension Logs folder and WAU-updates.log exists, make symlink - if ((Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs" -ErrorAction SilentlyContinue) -and !(Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log" -ErrorAction SilentlyContinue)) { - Write-ToLog "-> Creating SymLink for log file (WAU-updates) in Intune Management Extension log folder" "yellow" - $null = New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-updates.log" -ItemType SymbolicLink -Value $LogFile -Force -ErrorAction SilentlyContinue - } - - # Check if Intune Management Extension Logs folder and WAU-install.log exists, make symlink - if ((Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs" -ErrorAction SilentlyContinue) -and (Test-Path -Path ('{0}\logs\install.log' -f $WorkingDir) -ErrorAction SilentlyContinue) -and !(Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ErrorAction SilentlyContinue)) { - Write-ToLog "-> Creating SymLink for log file (WAU-install) in Intune Management Extension log folder" "yellow" - $null = (New-Item -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-install.log" -ItemType SymbolicLink -Value ('{0}\logs\install.log' -f $WorkingDir) -Force -Confirm:$False -ErrorAction SilentlyContinue) - } - #Update Winget if not up to date $null = Update-WinGet