-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-TSScanServer.ps1
More file actions
210 lines (174 loc) · 7.61 KB
/
Install-TSScanServer.ps1
File metadata and controls
210 lines (174 loc) · 7.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#Requires -Version 5.0
<#
.SYNOPSIS
Installs TSScan Server with interactive GUI support for Intune SYSTEM context deployment.
.DESCRIPTION
Installs TSScan_server.exe in interactive mode for use with ServiceUI.exe.
This script is called by Launch-TSScanInstall.bat, which is itself launched by
ServiceUI.exe. This two-stage approach ensures that both PowerShell AND the
TSScan GUI wizard are projected into the active user session.
After successful installation, the TSScan license file (tsscan-site.twlic) is
automatically copied to the appropriate location.
Session flow:
Intune (Session 0 SYSTEM)
-> ServiceUI.exe -process:explorer.exe
-> Launch-TSScanInstall.bat (now in user Session 1+)
-> powershell.exe (inherits user session)
-> TSScan_server.exe (GUI visible to user)
.PARAMETER LogPath
Directory for log files. Defaults to C:\softdist\Logs\TSScanServer.
.PARAMETER LicenseFileName
Name of the license file to deploy. Defaults to tsscan-site.twlic.
.EXAMPLE
.\Install-TSScanServer.ps1
Standard installation called via Launch-TSScanInstall.bat through ServiceUI.
.EXAMPLE
.\Install-TSScanServer.ps1 -LogPath "C:\Temp\Logs" -Verbose
Installation with custom log path and verbose output.
.EXAMPLE
.\Install-TSScanServer.ps1 -WhatIf
Test mode - shows what would happen without making changes.
.NOTES
Version: 2.0
Author: IT Infrastructure
Purpose: Intune Win32 App - Available (SYSTEM install, interactive via ServiceUI)
Package files: TSScan_server.exe, TSScan-site.twlic, ServiceUIx64.exe,
Launch-TSScanInstall.bat, Install-TSScanServer.ps1
Intune Install Command:
ServiceUIx64.exe -process:explorer.exe Launch-TSScanInstall.bat
Intune Uninstall Command:
powershell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -File "Uninstall-TSScanServer.ps1"
Install Behavior: System
Deployment type: Available (Company Portal)
#>
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter()]
[string]$LogPath = 'C:\softdist\Logs\TSScanServer',
[Parameter()]
[string]$LicenseFileName = 'TSScan-site.twlic'
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
#region --- Logging -----------------------------------------------------------
function Write-Log {
param(
[string]$Message,
[ValidateSet('INFO', 'WARN', 'ERROR', 'SUCCESS')]
[string]$Level = 'INFO'
)
$timestamp = Get-Date -Format 'yyyy-MM-dd HH:mm:ss'
$entry = "[$timestamp] [$Level] $Message"
# Console output
switch ($Level) {
'WARN' { Write-Warning $Message }
'ERROR' { Write-Error $Message -ErrorAction Continue }
'SUCCESS' { Write-Verbose $Message }
default { Write-Verbose $Message }
}
# File output
try {
Add-Content -Path $script:LogFile -Value $entry -Encoding UTF8
} catch {
# Suppress logging errors to avoid masking the real error
}
}
#endregion
#region --- Initialise --------------------------------------------------------
# Resolve the package root directory (same folder as this script)
$ScriptRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
# Ensure log directory exists
if (-not (Test-Path $LogPath)) {
New-Item -ItemType Directory -Path $LogPath -Force | Out-Null
}
$script:LogFile = Join-Path $LogPath "Install_TSScanServer_$(Get-Date -Format 'yyyyMMdd_HHmmss').log"
Write-Log "===== TSScan Server Installation Started ====="
Write-Log "Script root : $ScriptRoot"
Write-Log "Log file : $script:LogFile"
Write-Log "Running as : $([System.Security.Principal.WindowsIdentity]::GetCurrent().Name)"
# Detect session context (informational)
try {
$sessionId = (Get-Process -Id $PID).SessionId
Write-Log "Session ID : $sessionId $(if ($sessionId -eq 0) { '(WARNING: Session 0 - GUI may not be visible)' } else { '(User session - GUI will be visible)' })"
} catch {
Write-Log "Session ID : Unable to determine" -Level WARN
}
#endregion
#region --- Validate package files -------------------------------------------
$InstallerPath = Join-Path $ScriptRoot 'TSScan_server.exe'
$LicensePath = Join-Path $ScriptRoot $LicenseFileName
if (-not (Test-Path $InstallerPath)) {
Write-Log "Installer not found: $InstallerPath" -Level ERROR
exit 2
}
Write-Log "Installer : $InstallerPath [FOUND]"
$LicenseFound = Test-Path $LicensePath
if ($LicenseFound) {
Write-Log "License file : $LicensePath [FOUND]"
} else {
Write-Log "License file : $LicensePath [NOT FOUND - will skip license deployment]" -Level WARN
}
#endregion
#region --- Run installer (interactive, no silent flags) ----------------------
Write-Log "Launching TSScan installer in interactive mode..."
Write-Log "The user should see the installation wizard on their screen."
if ($PSCmdlet.ShouldProcess($InstallerPath, 'Run interactive installer')) {
try {
# Start the installer with NO silent flags so the wizard appears to the user.
# Because ServiceUI has already projected this PowerShell process into the user
# session, child processes (including the TSScan wizard) inherit that session
# and are therefore visible on the user's desktop.
$proc = Start-Process -FilePath $InstallerPath `
-Wait `
-PassThru
$exitCode = $proc.ExitCode
Write-Log "Installer finished with exit code: $exitCode"
switch ($exitCode) {
0 { Write-Log "Installation completed successfully." -Level SUCCESS }
1602 { Write-Log "User cancelled the installation (exit 1602)." -Level WARN ; exit 1602 }
1223 { Write-Log "User cancelled the installation (exit 1223)." -Level WARN ; exit 1223 }
3010 { Write-Log "Installation successful - reboot required (exit 3010)." -Level SUCCESS }
default {
Write-Log "Installer returned unexpected exit code: $exitCode" -Level WARN
# Do not immediately fail - verify installation below
}
}
} catch {
Write-Log "Failed to launch installer: $_" -Level ERROR
exit 1
}
}
#endregion
#region --- Verify installation -----------------------------------------------
Write-Log "Verifying installation..."
$installPaths = @(
'C:\Program Files (x86)\TerminalWorks\TSScan Server',
'C:\Program Files\TerminalWorks\TSScan Server'
)
$installedPath = $installPaths | Where-Object { Test-Path $_ } | Select-Object -First 1
if (-not $installedPath) {
Write-Log "Installation verification FAILED - install directory not found." -Level ERROR
Write-Log "Checked paths: $($installPaths -join ', ')"
exit 1
}
Write-Log "Installation verified at: $installedPath" -Level SUCCESS
#endregion
#region --- Deploy license file -----------------------------------------------
if ($LicenseFound) {
Write-Log "Deploying license file to: $installedPath"
if ($PSCmdlet.ShouldProcess($installedPath, 'Copy license file')) {
try {
Copy-Item -Path $LicensePath -Destination $installedPath -Force
Write-Log "License file deployed successfully." -Level SUCCESS
} catch {
# Non-fatal: log the error but do not fail the install
Write-Log "Failed to copy license file: $_" -Level WARN
Write-Log "Manual license deployment may be required." -Level WARN
}
}
} else {
Write-Log "Skipping license deployment (file not found in package)." -Level WARN
}
#endregion
Write-Log "===== TSScan Server Installation Completed Successfully ====="
exit 0