Logging done

pull/628/head
KnifMelti 2024-05-20 03:13:36 +02:00
parent 1fd3fe060a
commit 1ad487e941
1 changed files with 21 additions and 4 deletions

View File

@ -22,15 +22,19 @@ $Script:SessionID = [System.Diagnostics.Process]::GetCurrentProcess().SessionId
#Check if running as system #Check if running as system
if ($IsSystem) { if ($IsSystem) {
#If log file doesn't exist, force create it
if (!(Test-Path -Path $LogFile)) {
New-Item -Path $LogFile -ItemType File -Force | Out-Null
}
# Check if Intune Management Extension Logs folder exists # Check if Intune Management Extension Logs folder exists
if ((Test-Path -Path "${env:ProgramData}\Microsoft\IntuneManagementExtension\Logs" -ErrorAction SilentlyContinue)) { 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) # Check if 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)) { if (!(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 $symLink = 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) # 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)) { 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) $symLink = (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 #Check if running with session ID 0
@ -41,20 +45,33 @@ if ($IsSystem) {
#Check if any connected user #Check if any connected user
$explorerprocesses = @(Get-CimInstance -Query "SELECT * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue) $explorerprocesses = @(Get-CimInstance -Query "SELECT * FROM Win32_Process WHERE Name='explorer.exe'" -ErrorAction SilentlyContinue)
if ($explorerprocesses.Count -gt 0) { if ($explorerprocesses.Count -gt 0) {
if ($symLink) {
$null = (New-Item "$WorkingDir\logs\symlink.txt" -Value $symLink -Force)
}
#Rerun WAU in system context with ServiceUI #Rerun WAU in system context with ServiceUI
& $WorkingDir\ServiceUI.exe -process:explorer.exe $env:windir\System32\wscript.exe \`"$WorkingDir\Invisible.vbs\`" \`"powershell.exe -NoProfile -ExecutionPolicy Bypass -File \`"\`"$WorkingDir\winget-upgrade.ps1\`"\`"\`" & $WorkingDir\ServiceUI.exe -process:explorer.exe $env:windir\System32\wscript.exe \`"$WorkingDir\Invisible.vbs\`" \`"powershell.exe -NoProfile -ExecutionPolicy Bypass -File \`"\`"$WorkingDir\winget-upgrade.ps1\`"\`"\`"
Exit 0 Exit 0
} }
else { else {
Write-ToLog -LogMsg "CHECK FOR APP UPDATES (System context)" -IsHeader Write-ToLog -LogMsg "CHECK FOR APP UPDATES (System context)" -IsHeader
if ($symLink) {
Write-ToLog "SymLink for log file created in Intune Management Extension log folder"
}
} }
} }
else { else {
Write-ToLog -LogMsg "CHECK FOR APP UPDATES (System context - No ServiceUI)" -IsHeader Write-ToLog -LogMsg "CHECK FOR APP UPDATES (System context - No ServiceUI)" -IsHeader
if ($symLink) {
Write-ToLog "SymLink for log file created in Intune Management Extension log folder"
}
} }
} }
else { else {
Write-ToLog -LogMsg "CHECK FOR APP UPDATES (System context - Connected user)" -IsHeader Write-ToLog -LogMsg "CHECK FOR APP UPDATES (System context - Connected user)" -IsHeader
if (Test-Path "$WorkingDir\logs\symlink.txt") {
Write-ToLog "SymLink for log file created in Intune Management Extension log folder"
Remove-Item "$WorkingDir\logs\symlink.txt" -Force
}
} }
} }
else { else {