Skip to content

Commit 4ffd27c

Browse files
authored
Merge pull request #1020 from Romanitho/remove-symlink
Remove Symlink + Log header location
2 parents 449fe57 + 91110ab commit 4ffd27c

File tree

1 file changed

+20
-63
lines changed

1 file changed

+20
-63
lines changed

Sources/Winget-AutoUpdate/Winget-Upgrade.ps1

Lines changed: 20 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,6 @@ $Script:ProgressPreference = [System.Management.Automation.ActionPreference]::Si
1919
# Log initialization
2020
[string]$LogFile = [System.IO.Path]::Combine($Script:WorkingDir, 'logs', 'updates.log');
2121

22-
#region Get settings and Domain/Local Policies (GPO) if activated.
23-
Write-ToLog "Reading WAUConfig";
24-
$Script:WAUConfig = Get-WAUConfig;
25-
#endregion Get settings and Domain/Local Policies (GPO) if activated.
26-
27-
# Default name of winget repository used within this script
28-
[string]$DefaultWingetRepoName = 'winget';
29-
30-
#region Winget Source Custom
31-
# Defining a custom source even if not used below (failsafe suggested by github/sebneus mentioned in issues/823)
32-
[string]$Script:WingetSourceCustom = $DefaultWingetRepoName;
33-
34-
# Defining custom repository for winget tool
35-
if ($null -ne $Script:WAUConfig.WAU_WingetSourceCustom) {
36-
$Script:WingetSourceCustom = $Script:WAUConfig.WAU_WingetSourceCustom.Trim();
37-
Write-ToLog "Selecting winget repository named '$($Script:WingetSourceCustom)'";
38-
}
39-
#endregion Winget Source Custom
40-
4122
#region Checking execution context
4223
# Check if running account is system or interactive logon System(default) otherwise User
4324
[bool]$Script:IsSystem = [System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem;
@@ -46,6 +27,7 @@ if ($null -ne $Script:WAUConfig.WAU_WingetSourceCustom) {
4627
[Int32]$Script:SessionID = [System.Diagnostics.Process]::GetCurrentProcess().SessionId;
4728
#endregion
4829

30+
#region Execution context and logging
4931
# Preparation to run in current context
5032
if ($true -eq $IsSystem) {
5133

@@ -54,50 +36,6 @@ if ($true -eq $IsSystem) {
5436
Write-ToLog "New log file created";
5537
}
5638

57-
# paths
58-
[string]$IntuneLogsDir = "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs";
59-
[string]$fp0 = [System.IO.Path]::Combine($IntuneLogsDir, 'WAU-updates.log');
60-
[string]$fp1 = [System.IO.Path]::Combine($Script:WorkingDir, 'logs', 'install.log');
61-
[string]$fp2 = [System.IO.Path]::Combine($IntuneLogsDir, 'WAU-install.log');
62-
63-
# Check if Intune Management Extension Logs folder exists
64-
if (Test-Path -Path $IntuneLogsDir -PathType Container -ErrorAction SilentlyContinue) {
65-
66-
# Check if symlink WAU-updates.log exists, make symlink (doesn't work under ServiceUI)
67-
if (!(Test-Path -Path $fp0 -ErrorAction SilentlyContinue)) {
68-
New-Item -Path $fp0 -ItemType SymbolicLink -Value $LogFile -Force -ErrorAction SilentlyContinue | Out-Null;
69-
Write-ToLog "SymLink for 'update' log file created in in $($IntuneLogsDir) folder";
70-
}
71-
72-
# Check if install.log and symlink WAU-install.log exists, make symlink (doesn't work under ServiceUI)
73-
if ( (Test-Path -Path $fp1 -ErrorAction SilentlyContinue) -and !(Test-Path -Path $fp2 -ErrorAction SilentlyContinue) ) {
74-
New-Item -Path $fp2 -ItemType SymbolicLink -Value $fp1 -Force -Confirm:$False -ErrorAction SilentlyContinue | Out-Null;
75-
Write-ToLog "SymLink for 'install' log file created in $($IntuneLogsDir) folder"
76-
}
77-
# Check if user install.log and symlink WAU-install-username.log exists, make symlink (doesn't work under ServiceUI)
78-
# Get all user directories from C:\Users (excluding default/system profiles)
79-
$UserDirs = Get-ChildItem -Path "C:\Users" -Directory | Where-Object {
80-
($_ -notmatch "Default") -and ($_ -notmatch "Public") -and ($_ -notmatch "All Users") -and ($_ -notmatch "Default User")
81-
}
82-
foreach ($UserDir in $UserDirs) {
83-
# Define user-specific log path and log file
84-
$UserLogPath = "$($UserDir.FullName)\AppData\Roaming\Winget-AutoUpdate\Logs"
85-
$UserLogFile = "$UserLogPath\install_$($UserDir.Name).log"
86-
87-
# Check if the user's log file exists
88-
if (Test-Path -Path $UserLogFile -ErrorAction SilentlyContinue) {
89-
# Define the Symlink target
90-
$UserLogLink = "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs\WAU-user_$($UserDir.Name).log"
91-
92-
# Create Symlink if it doesn't already exist
93-
if (!(Test-Path -Path $UserLogLink -ErrorAction SilentlyContinue)) {
94-
New-Item -Path $UserLogLink -ItemType SymbolicLink -Value $UserLogFile -Force -ErrorAction SilentlyContinue | Out-Null
95-
Write-ToLog "Created Symlink for user log: $UserLogLink -> $UserLogFile"
96-
}
97-
}
98-
}
99-
}
100-
10139
#Check if running with session ID 0
10240
if ($SessionID -eq 0) {
10341
#Check if ServiceUI exists
@@ -131,6 +69,25 @@ else {
13169
Write-ToLog -LogMsg "CHECK FOR APP UPDATES (User context)" -IsHeader
13270
}
13371

72+
#region Get settings and Domain/Local Policies (GPO) if activated.
73+
Write-ToLog "Reading WAUConfig";
74+
$Script:WAUConfig = Get-WAUConfig;
75+
#endregion Get settings and Domain/Local Policies (GPO) if activated.
76+
77+
# Default name of winget repository used within this script
78+
[string]$DefaultWingetRepoName = 'winget';
79+
80+
#region Winget Source Custom
81+
# Defining a custom source even if not used below (failsafe suggested by github/sebneus mentioned in issues/823)
82+
[string]$Script:WingetSourceCustom = $DefaultWingetRepoName;
83+
84+
# Defining custom repository for winget tool
85+
if ($null -ne $Script:WAUConfig.WAU_WingetSourceCustom) {
86+
$Script:WingetSourceCustom = $Script:WAUConfig.WAU_WingetSourceCustom.Trim();
87+
Write-ToLog "Selecting winget repository named '$($Script:WingetSourceCustom)'";
88+
}
89+
#endregion Winget Source Custom
90+
13491
#region Log running context
13592
if ($true -eq $IsSystem) {
13693

0 commit comments

Comments
 (0)