-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInstall-BloombergClient.ps1
More file actions
367 lines (308 loc) · 14.4 KB
/
Install-BloombergClient.ps1
File metadata and controls
367 lines (308 loc) · 14.4 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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<#
.SYNOPSIS
Installs Bloomberg Terminal client application for enterprise deployment via Intune.
.DESCRIPTION
This script performs a silent installation of the Bloomberg Terminal client application.
Designed for deployment through Microsoft Intune as a Win32 application package.
Automatically closes Office 365 applications (Excel, Word, PowerPoint) before installation
as required by Bloomberg Terminal installer. Includes comprehensive logging, error handling,
and exit codes for deployment monitoring.
.PARAMETER InstallerPath
Path to the Bloomberg installer executable file. Defaults to the script directory.
.PARAMETER LogPath
Path where installation logs will be written. Defaults to C:\softdist\Logs\Bloomberg.
.NOTES
WhatIf parameter is automatically available through SupportsShouldProcess.
Use -WhatIf to preview actions without executing them.
.EXAMPLE
.\Install-BloombergClient.ps1
Performs a silent installation using the default installer in the script directory.
.EXAMPLE
.\Install-BloombergClient.ps1 -InstallerPath "C:\Temp\BloombergInstaller.exe" -Verbose
Installs Bloomberg client with verbose output, custom installer path, and closes any running Office apps.
.EXAMPLE
.\Install-BloombergClient.ps1 -WhatIf
Shows what would be done including Office app closure without actually installing.
.NOTES
File Name : Install-BloombergClient.ps1
Author : IT Infrastructure Team
Prerequisite : PowerShell 5.1 or later, Administrative privileges
Requirements : Bloomberg installer executable must be present
Exit Codes:
0 = Success
1 = General error
2 = Installer file not found
3 = Installation failed
4 = Post-installation verification failed
5 = Insufficient privileges
#>
#Requires -Version 5.1
#Requires -RunAsAdministrator
[CmdletBinding(SupportsShouldProcess)]
param(
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$InstallerPath,
[Parameter(Mandatory = $false)]
[ValidateNotNullOrEmpty()]
[string]$LogPath = "C:\softdist\Logs\Bloomberg"
)
# Script variables
$ScriptName = "Install-BloombergClient"
$ScriptVersion = "1.0.0"
$ExitCode = 0
$StartTime = Get-Date
# Initialize logging
try {
if (-not (Test-Path -Path $LogPath)) {
New-Item -Path $LogPath -ItemType Directory -Force | Out-Null
}
$LogFile = Join-Path -Path $LogPath -ChildPath "$ScriptName-$(Get-Date -Format 'yyyyMMdd-HHmmss').log"
Start-Transcript -Path $LogFile -Append
Write-Host "[$ScriptName] Starting Bloomberg Terminal installation" -ForegroundColor Green
Write-Host "[$ScriptName] Script Version: $ScriptVersion" -ForegroundColor Green
Write-Host "[$ScriptName] Log file: $LogFile" -ForegroundColor Green
Write-Host "[$ScriptName] Start time: $StartTime" -ForegroundColor Green
Write-Host "[$ScriptName] Running as: $env:USERNAME" -ForegroundColor Green
}
catch {
Write-Error "Failed to initialize logging: $($_.Exception.Message)"
exit 1
}
try {
# Determine installer path
if (-not $InstallerPath) {
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$PossibleInstallers = @(
"BloombergInstaller.exe",
"bloomberg_terminal_installer.exe",
"Bloomberg Terminal Installer.exe"
)
foreach ($Installer in $PossibleInstallers) {
$TestPath = Join-Path -Path $ScriptDir -ChildPath $Installer
if (Test-Path -Path $TestPath) {
$InstallerPath = $TestPath
break
}
}
# If no predefined installer found, look for any .exe file
if (-not $InstallerPath) {
$ExeFiles = Get-ChildItem -Path $ScriptDir -Filter "*.exe" | Where-Object { $_.Name -like "*bloomberg*" -or $_.Name -like "*terminal*" }
if ($ExeFiles.Count -eq 1) {
$InstallerPath = $ExeFiles[0].FullName
}
}
}
# Validate installer exists
if (-not $InstallerPath -or -not (Test-Path -Path $InstallerPath)) {
Write-Error "Bloomberg installer not found. Please ensure the installer executable is in the script directory or specify -InstallerPath"
Write-Host "[$ScriptName] Searched locations:" -ForegroundColor Yellow
if ($ScriptDir) {
Write-Host " - $ScriptDir\BloombergInstaller.exe" -ForegroundColor Yellow
Write-Host " - $ScriptDir\bloomberg_terminal_installer.exe" -ForegroundColor Yellow
Write-Host " - $ScriptDir\Bloomberg Terminal Installer.exe" -ForegroundColor Yellow
}
$ExitCode = 2
throw "Installer file not found"
}
Write-Host "[$ScriptName] Found installer: $InstallerPath" -ForegroundColor Green
# Get installer file info
$InstallerInfo = Get-Item -Path $InstallerPath
Write-Host "[$ScriptName] Installer size: $([math]::Round($InstallerInfo.Length / 1MB, 2)) MB" -ForegroundColor Green
Write-Host "[$ScriptName] Installer modified: $($InstallerInfo.LastWriteTime)" -ForegroundColor Green
# Check for and close Office 365 applications before installation
Write-Host "[$ScriptName] Checking for running Office 365 applications..." -ForegroundColor Yellow
$OfficeProcesses = @(
@{ Name = "EXCEL"; DisplayName = "Microsoft Excel" },
@{ Name = "WINWORD"; DisplayName = "Microsoft Word" },
@{ Name = "POWERPNT"; DisplayName = "Microsoft PowerPoint" }
)
$RunningOfficeApps = @()
foreach ($OfficeApp in $OfficeProcesses) {
$Processes = Get-Process -Name $OfficeApp.Name -ErrorAction SilentlyContinue
if ($Processes) {
$RunningOfficeApps += @{
ProcessName = $OfficeApp.Name
DisplayName = $OfficeApp.DisplayName
Processes = $Processes
}
}
}
if ($RunningOfficeApps.Count -gt 0) {
Write-Host "[$ScriptName] Found running Office 365 applications that need to be closed:" -ForegroundColor Yellow
foreach ($App in $RunningOfficeApps) {
Write-Host " - $($App.DisplayName) ($($App.Processes.Count) instance(s))" -ForegroundColor Yellow
}
Write-Host "[$ScriptName] Bloomberg Terminal requires Office applications to be closed before installation" -ForegroundColor Yellow
Write-Host "[$ScriptName] Attempting to gracefully close Office applications..." -ForegroundColor Yellow
$ClosureSuccess = $true
foreach ($App in $RunningOfficeApps) {
foreach ($Process in $App.Processes) {
try {
Write-Host "[$ScriptName] Closing $($App.DisplayName) (PID: $($Process.Id))..." -ForegroundColor Gray
# First attempt graceful closure
$Process.CloseMainWindow() | Out-Null
# Wait up to 10 seconds for graceful closure
$WaitCount = 0
while (-not $Process.HasExited -and $WaitCount -lt 10) {
Start-Sleep -Seconds 1
$WaitCount++
}
# If still running, force termination
if (-not $Process.HasExited) {
Write-Warning "[$ScriptName] Graceful closure failed, force terminating $($App.DisplayName) (PID: $($Process.Id))"
$Process.Kill()
Start-Sleep -Seconds 2
}
if ($Process.HasExited) {
Write-Host "[$ScriptName] Successfully closed $($App.DisplayName) (PID: $($Process.Id))" -ForegroundColor Green
}
else {
Write-Warning "[$ScriptName] Failed to close $($App.DisplayName) (PID: $($Process.Id))"
$ClosureSuccess = $false
}
}
catch {
Write-Warning "[$ScriptName] Error closing $($App.DisplayName): $($_.Exception.Message)"
$ClosureSuccess = $false
}
}
}
# Final verification that Office apps are closed
Start-Sleep -Seconds 3
$StillRunning = @()
foreach ($OfficeApp in $OfficeProcesses) {
$RemainingProcesses = Get-Process -Name $OfficeApp.Name -ErrorAction SilentlyContinue
if ($RemainingProcesses) {
$StillRunning += @{
ProcessName = $OfficeApp.Name
DisplayName = $OfficeApp.DisplayName
Count = $RemainingProcesses.Count
}
}
}
if ($StillRunning.Count -gt 0) {
Write-Error "[$ScriptName] Some Office applications are still running after closure attempt:"
foreach ($App in $StillRunning) {
Write-Error " - $($App.DisplayName) ($($App.Count) instance(s))"
}
Write-Warning "[$ScriptName] Bloomberg installation may fail or encounter issues with Office apps running"
Write-Warning "[$ScriptName] Continuing with installation attempt..."
}
else {
Write-Host "[$ScriptName] All Office applications successfully closed" -ForegroundColor Green
}
}
else {
Write-Host "[$ScriptName] No Office 365 applications found running" -ForegroundColor Green
}
# Note: Intune handles installation detection separately
Write-Host "[$ScriptName] Proceeding with Bloomberg Terminal installation..." -ForegroundColor Yellow
# Prepare installation command
$InstallArgs = @(
'/S', # Silent install
'/v/qn' # MSI quiet mode (if applicable)
)
# Additional silent install arguments that might be needed
$AdditionalArgs = @(
'/SILENT',
'/VERYSILENT',
'/SUPPRESSMSGBOXES',
'/NORESTART'
)
$InstallCommand = "& '$InstallerPath' $($InstallArgs -join ' ')"
if ($WhatIf) {
Write-Host "[$ScriptName] WhatIf: Would check for and close Office 365 applications (Excel, Word, PowerPoint)" -ForegroundColor Magenta
Write-Host "[$ScriptName] WhatIf: Would execute: $InstallCommand" -ForegroundColor Magenta
Write-Host "[$ScriptName] WhatIf: Installation would be performed silently" -ForegroundColor Magenta
Write-Host "[$ScriptName] WhatIf: Would create detection tag file at C:\temp\Bloomberg_Installed.tag" -ForegroundColor Magenta
exit 0
}
# Perform installation
Write-Host "[$ScriptName] Starting Bloomberg Terminal installation..." -ForegroundColor Yellow
Write-Host "[$ScriptName] Command: $InstallCommand" -ForegroundColor Gray
$InstallStartTime = Get-Date
# Execute installation with different argument sets
$InstallSuccess = $false
$InstallAttempts = @(
@('/S', '/v/qn'),
@('/SILENT', '/SUPPRESSMSGBOXES', '/NORESTART'),
@('/VERYSILENT', '/SUPPRESSMSGBOXES', '/NORESTART'),
@('/S'),
@('/q')
)
foreach ($AttemptArgs in $InstallAttempts) {
try {
Write-Host "[$ScriptName] Attempting installation with args: $($AttemptArgs -join ' ')" -ForegroundColor Gray
$Process = Start-Process -FilePath $InstallerPath -ArgumentList $AttemptArgs -Wait -PassThru -NoNewWindow
if ($Process.ExitCode -eq 0) {
Write-Host "[$ScriptName] Installation completed successfully with exit code: $($Process.ExitCode)" -ForegroundColor Green
$InstallSuccess = $true
break
}
else {
Write-Warning "[$ScriptName] Installation attempt failed with exit code: $($Process.ExitCode)"
}
}
catch {
Write-Warning "[$ScriptName] Installation attempt failed: $($_.Exception.Message)"
}
Start-Sleep -Seconds 2
}
if (-not $InstallSuccess) {
Write-Error "[$ScriptName] All installation attempts failed"
$ExitCode = 3
throw "Installation failed with all attempted argument sets"
}
$InstallEndTime = Get-Date
$InstallDuration = $InstallEndTime - $InstallStartTime
Write-Host "[$ScriptName] Installation duration: $($InstallDuration.TotalMinutes.ToString('F2')) minutes" -ForegroundColor Green
# Create tag file for Intune detection
Write-Host "[$ScriptName] Creating detection tag file for Intune..." -ForegroundColor Yellow
try {
$TagFilePath = "C:\temp\Bloomberg_Installed.tag"
$TagFileContent = @"
Bloomberg Terminal Installation Tag File
Installation Date: $(Get-Date -Format 'yyyy-MM-dd HH:mm:ss')
Script Version: $ScriptVersion
Installed By: $env:USERNAME
Computer: $env:COMPUTERNAME
Bloomberg Installation: C:\blp
Installation Method: Successfully Completed
"@
# Ensure C:\temp directory exists
if (-not (Test-Path -Path "C:\temp")) {
New-Item -Path "C:\temp" -ItemType Directory -Force | Out-Null
Write-Host "[$ScriptName] Created C:\temp directory" -ForegroundColor Green
}
# Create tag file
Set-Content -Path $TagFilePath -Value $TagFileContent -Force
Write-Host "[$ScriptName] Created detection tag file: $TagFilePath" -ForegroundColor Green
}
catch {
Write-Warning "[$ScriptName] Failed to create tag file: $($_.Exception.Message)"
# Don't fail installation for tag file creation failure
}
Write-Host "[$ScriptName] Bloomberg Terminal installation completed successfully" -ForegroundColor Green
}
catch {
Write-Error "[$ScriptName] Installation failed: $($_.Exception.Message)"
Write-Error "[$ScriptName] Full error: $($_.Exception | Format-List * | Out-String)"
if ($ExitCode -eq 0) {
$ExitCode = 1
}
}
finally {
$EndTime = Get-Date
$TotalDuration = $EndTime - $StartTime
Write-Host "[$ScriptName] Script execution completed" -ForegroundColor Green
Write-Host "[$ScriptName] Total duration: $($TotalDuration.TotalMinutes.ToString('F2')) minutes" -ForegroundColor Green
Write-Host "[$ScriptName] Exit code: $ExitCode" -ForegroundColor Green
try {
Stop-Transcript
}
catch {
# Transcript may not have started successfully
}
exit $ExitCode
}