From b9461d104a72024fcbe6ef59a7743029ede3df6e Mon Sep 17 00:00:00 2001 From: CristianD Date: Tue, 1 Sep 2026 13:08:54 +0100 Subject: [PATCH] Update 8x8_Work_Updater.ps1 --- 8x8_Work_Updater.ps1 | 80 +++++++++++++++++++++++++++++++------------- 1 file changed, 57 insertions(+), 23 deletions(-) diff --git a/8x8_Work_Updater.ps1 b/8x8_Work_Updater.ps1 index 4768520..649dfd7 100644 --- a/8x8_Work_Updater.ps1 +++ b/8x8_Work_Updater.ps1 @@ -1,8 +1,9 @@ # ============================================================================== # Script Name: 8x8_Work_Updater.ps1 # Description: Downloads 8x8 with a progress bar, detects the active interactive -# desktop user dynamically, presents the unclosable HTA countdown -# prompt, installs silently, and relaunches 8x8 Work. +# desktop user, presents the unclosable HTA countdown prompt, +# installs silently, relaunches 8x8 Work, and logs everything to +# C:\IntuneLogs\8x8Updater_log.txt. # ============================================================================== # Ensure script is running elevated @@ -13,6 +14,29 @@ if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti Add-Type -AssemblyName System.Net.Http +# Configure logging directory and log file +$logDir = "C:\IntuneLogs" +$logFile = Join-Path $logDir "8x8Updater_log.txt" + +if (-not (Test-Path $logDir)) { + New-Item -Path $logDir -ItemType Directory -Force | Out-Null +} + +function Write-Log { + param ( + [string]$Message, + [ConsoleColor]$Color = [ConsoleColor]::Gray + ) + $timestamp = (Get-Date).ToString("yyyy-MM-dd HH:mm:ss") + $logLine = "[$timestamp] $Message" + + # Output to Console + Write-Host $Message -ForegroundColor $Color + + # Append to Log File + Add-Content -Path $logFile -Value $logLine -Force +} + $workDir = "C:\ProgramData\JCT600_8x8Update" $flagFile = Join-Path $workDir "8x8_Update_Proceed.flag" $htaPromptPath = Join-Path $workDir "Show-8x8Prompt.hta" @@ -29,12 +53,14 @@ Set-Acl $workDir $acl if (Test-Path $flagFile) { Remove-Item $flagFile -Force } +Write-Log "========== Starting 8x8 Work Update Script ==========" -Color Cyan + try { # -------------------------------------------------------------------------- # Step 1: Download 8x8 Setup Installer with Console Progress Bar # -------------------------------------------------------------------------- $installerUrl = "https://work-desktop-assets.8x8.com/prod-publish/ga/work-64-msi-v8.36.2-3.msi" - Write-Host "[1/4] Downloading 8x8 Work installer..." -ForegroundColor Cyan + Write-Log "[1/4] Downloading 8x8 Work installer from $installerUrl..." -Color Cyan try { $httpClient = New-Object System.Net.Http.HttpClient @@ -63,22 +89,23 @@ try { } } $outputStream.Close(); $inputStream.Close(); $httpClient.Dispose() - Write-Host "`nDownload complete: $installerPath" -ForegroundColor Green + Write-Host "" # Newline after progress bar + Write-Log "Download complete: $installerPath ($([math]::Round($totalBytesRead / 1MB, 2)) MB)" -Color Green } catch { - Write-Error "`nFailed to download installer. Error: $_" + Write-Log "Failed to download installer. Error: $_" -Color Red exit 1 } # -------------------------------------------------------------------------- # Step 2: Generate Sleep-Safe Wall-Clock HTA Countdown Dialog # -------------------------------------------------------------------------- - Write-Host "[2/4] Generating sleep-safe unclosable dialog..." -ForegroundColor Cyan + Write-Log "[2/4] Generating sleep-safe unclosable dialog..." -Color Cyan $htaContent = @" - JCT600 IT Support - 8x8 Work Update + JCT600 IT Support — 8x8 Work Update -
JCT600 - IT SUPPORT
+
JCT600 — IT SUPPORT
An automatic update for 8x8 Work has been scheduled.
Please save active work or click Update Now to begin. @@ -195,21 +222,19 @@ try { # -------------------------------------------------------------------------- # Step 3: Detect Active Desktop User & Launch HTA Prompt # -------------------------------------------------------------------------- - Write-Host "[3/4] Detecting active console user and launching dialog..." -ForegroundColor Cyan + Write-Log "[3/4] Detecting active console user and launching dialog..." -Color Cyan $explorerProc = Get-Process -Name explorer -ErrorAction SilentlyContinue | Select-Object -First 1 if (-not $explorerProc) { - Write-Warning "No active interactive desktop detected. Proceeding directly to update." + Write-Log "No active interactive desktop detected. Proceeding directly to update." -Color Yellow } else { - # Query owner domain\username directly from explorer process - $ownerInfo = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $($explorerProc.Id)" | Invoke-CimMethod -MethodName GetOwner + $ownerInfo = Get-CimInstance -ClassName Win32_Process -Filter "ProcessId = $($explorerProc.Id)" | Invoke-CimMethod -MethodName GetOwner $activeUser = "$($ownerInfo.Domain)\$($ownerInfo.User)" - Write-Host "Active Desktop User: $activeUser" -ForegroundColor Green + Write-Log "Active Desktop User: $activeUser (Session ID: $($explorerProc.SessionId))" -Color Green $taskName = "JCT600_8x8_UpdatePrompt" - # Register Scheduled Task targeting the interactive token of the active user $action = New-ScheduledTaskAction -Execute "mshta.exe" -Argument "`"$htaPromptPath`"" $trigger = New-ScheduledTaskTrigger -At (Get-Date).AddSeconds(2) -Once $principal = New-ScheduledTaskPrincipal -UserId $activeUser -LogonType Interactive -RunLevel Limited @@ -218,18 +243,19 @@ try { Register-ScheduledTask -TaskName $taskName -Action $action -Trigger $trigger -Principal $principal -Settings $settings -Force | Out-Null Start-ScheduledTask -TaskName $taskName | Out-Null - Write-Host "Dialog prompt active. Waiting for user action or 1-hour expiration..." -ForegroundColor Yellow + Write-Log "Dialog prompt active. Waiting for user action or 1-hour expiration..." -Color Yellow while (-not (Test-Path $flagFile)) { Start-Sleep -Seconds 2 } + Write-Log "User action/timeout received. Proceeding with installation." -Color Green Unregister-ScheduledTask -TaskName $taskName -Confirm:$false -ErrorAction SilentlyContinue } # -------------------------------------------------------------------------- # Step 4: Close 8x8 Processes & Install Silently # -------------------------------------------------------------------------- - Write-Host "[4/4] Stopping 8x8 processes and installing silently..." -ForegroundColor Cyan + Write-Log "[4/4] Stopping active 8x8 processes and installing silently..." -Color Cyan $targetProcesses = Get-Process | Where-Object { $_.ProcessName -like "*8x8*" -or $_.MainWindowTitle -like "*8x8*" @@ -237,25 +263,29 @@ try { if ($targetProcesses) { foreach ($proc in $targetProcesses) { + Write-Log "Stopping process: $($proc.ProcessName) (PID: $($proc.Id))" -Color Yellow Stop-Process -Id $proc.Id -Force -ErrorAction SilentlyContinue } Start-Sleep -Seconds 3 } - $msiArgs = "/i `"$installerPath`" /quiet /norestart" + $msiLogPath = Join-Path $logDir "8x8_MSI_Install.log" + $msiArgs = "/i `"$installerPath`" /quiet /norestart /lv* `"$msiLogPath`"" + + Write-Log "Executing: msiexec.exe $msiArgs" -Color Cyan $installJob = Start-Process msiexec.exe -ArgumentList $msiArgs -Wait -PassThru if ($installJob.ExitCode -ne 0 -and $installJob.ExitCode -ne 3010) { - Write-Error "Installation failed with exit code $($installJob.ExitCode)." + Write-Log "MSI Installation failed with exit code $($installJob.ExitCode)." -Color Red exit $installJob.ExitCode } - Write-Host "Installation completed successfully." -ForegroundColor Green + Write-Log "MSI Installation completed successfully with ExitCode $($installJob.ExitCode)." -Color Green # -------------------------------------------------------------------------- # Step 5: Relaunch 8x8 Work in Active User Session # -------------------------------------------------------------------------- - Write-Host "Launching 8x8 Work..." -ForegroundColor Cyan + Write-Log "Launching updated 8x8 Work..." -Color Cyan $possiblePaths = @( "${env:ProgramFiles}\8x8 Inc\8x8 Work\8x8 Work.exe", @@ -278,17 +308,21 @@ try { Start-Sleep -Seconds 4 Unregister-ScheduledTask -TaskName $launchTask -Confirm:$false -ErrorAction SilentlyContinue - Write-Host "8x8 Work launched successfully." -ForegroundColor Green + Write-Log "8x8 Work launched successfully for $activeUser." -Color Green } else { Start-Process "explorer.exe" -ArgumentList "`"$exePath`"" + Write-Log "8x8 Work started via explorer.exe fallback." -Color Green } } else { - Write-Warning "Could not locate 8x8 Work executable." + Write-Log "Could not locate 8x8 Work executable on disk." -Color Yellow } +} catch { + Write-Log "Unexpected script error: $_" -Color Red } finally { - Write-Host "Cleaning up temporary files..." -ForegroundColor Gray + Write-Log "Cleaning up temporary files..." -Color Gray if (Test-Path $workDir) { Remove-Item $workDir -Recurse -Force -ErrorAction SilentlyContinue } + Write-Log "========== 8x8 Work Update Script Finished ==========" -Color Cyan } \ No newline at end of file