forked from MicksITBlogs/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMSIAnalyzer.ps1
605 lines (556 loc) · 28.7 KB
/
MSIAnalyzer.ps1
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
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
<#
.NOTES
===========================================================================
Created with: SAPIEN Technologies, Inc., PowerShell Studio 2015 v4.2.90
Created on: 27 July 2015 9:24 AM
Created by: Mick Pletcher
Filename: MSIAnalyzer.ps1
===========================================================================
.DESCRIPTION
This script will uninstall all previous versions of SCCM Client,
including the execution of the ccmclean.exe to rid the system of
any remnants of the previous client. It will then install the new
client and wait until the client is installed and is communicating
with the SCCM server.
#>
#Declare Global Variables
Set-Variable -Name ApplicationName -Scope Global -Force
Set-Variable -Name MSI -Scope Global -Force
Set-Variable -Name ProductCode -Scope Global -Force
function Get-RelativePath {
#Declare Local Variables
Set-Variable -Name RelativePath -Scope Local -Force
$RelativePath = (split-path $SCRIPT:MyInvocation.MyCommand.Path -parent) + "\"
Return $RelativePath
#Cleanup Local Variables
Remove-Variable -Name RelativePath -Scope Local -Force
}
function Get-Architecture {
#Declare Local Variables
Set-Variable -Name Architecture -Scope Local -Force
$Architecture = Get-WmiObject -Class Win32_OperatingSystem | Select-Object OSArchitecture
$Architecture = $Global:Architecture.OSArchitecture
Return $Architecture
#Cleanup Local Variables
Remove-Variable -Name Architecture -Scope Local -Force
}
function ProcessTextFiles {
#Declare Local Variables
Set-Variable -Name RelativePath -Scope Local -Force
If ((Test-Path -Path $RelativePath"Installer.log") -eq $true) {
Remove-Item -Path $RelativePath"Installer.log" -Force
}
If ((Test-Path -Path $RelativePath"UserInput.txt") -eq $true) {
Remove-Item -Path $RelativePath"UserInput.txt" -Force
}
If ((Test-Path -Path $RelativePath"Report.txt") -eq $true) {
Remove-Item -Path $RelativePath"Report.txt" -Force
}
#Cleanup Local Variables
Remove-Variable -Name RelativePath -Scope Local -Force
}
function Get-MSIFile {
#Declare Local Variables
Set-Variable -Name FileCount -Value 1 -Scope Local -Force
Set-Variable -Name MSIFile -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
$RelativePath = Get-RelativePath
$MSIFile = Get-ChildItem $RelativePath -Filter *.msi
Write-Host $MSIFile.Count
If ($MSIFile.Count -eq 1) {
Return $MSIFile
} else {
Do {
Clear-Host
$FileCount = 1
Write-Host "Select MSI to process:"
foreach ($MSI in $MSIFile) {
Write-Host $FileCount" - "$MSI
$FileCount++
}
Write-Host
Write-Host "Selection:"
[int]$input = Read-Host
} while (($input -eq $null) -or ($input -eq "") -or ($input -gt $MSIFile.Count) -or (!($input -as [int] -is [int])))
$input = $input - 1
$MSIFile = $MSIFile[$input]
$global:MSI = $RelativePath + $MSIFile
}
#Cleanup Local Variables
Remove-Variable -Name FileCount -Scope Local -Force
Remove-Variable -Name MSIFile -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
}
function Get-MSIFileInfo {
param (
[parameter(Mandatory = $true)][IO.FileInfo]
$Path,
[parameter(Mandatory = $true)][ValidateSet("ProductCode", "ProductVersion", "ProductName")][string]
$Property
)
#Declare Local Variables
Set-Variable -Name MSIDatabase -Scope Local -Force
Set-Variable -Name Query -Scope Local -Force
Set-Variable -Name Record -Scope Local -Force
Set-Variable -Name Value -Scope Local -Force
Set-Variable -Name View -Scope Local -Force
Set-Variable -Name WindowsInstaller -Scope Local -Force
try {
$WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $Null, $WindowsInstaller, @($Path.FullName, 0))
$Query = "SELECT Value FROM Property WHERE Property = '$($Property)'"
$View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $null, $View, $null)
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $View, $null)
$Value = $Record.GetType().InvokeMember("StringData", "GetProperty", $null, $Record, 1)
return $Value
} catch {
Write-Output $_.Exception.Message
}
#Declare Local Variables
Remove-Variable -Name MSIDatabase -Scope Local -Force
Remove-Variable -Name Query -Scope Local -Force
Remove-Variable -Name Record -Scope Local -Force
Remove-Variable -Name Value -Scope Local -Force
Remove-Variable -Name View -Scope Local -Force
Remove-Variable -Name WindowsInstaller -Scope Local -Force
}
function New-UserInputFile {
#Declare Local Variables
Set-Variable -Name ErrCode -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
$RelativePath = Get-RelativePath
If ((Test-Path -Path $RelativePath"UserInput.txt") -eq $true) {
Remove-Item -Path $RelativePath"UserInput.txt" -Force
}
Write-Host "Creating UserInput.txt File....." -NoNewline
$ErrCode = New-Item -Path $RelativePath"UserInput.txt" -Type File -Force
If ((Test-Path -Path $RelativePath"UserInput.txt") -eq $true) {
Write-Host "Success" -ForegroundColor Yellow
} else {
Write-Host "Failed" -ForegroundColor Red
}
#Cleanup Local Variables
Remove-Variable -Name ErrCode -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
}
function Install-MSI {
#Declare Local Variables
Set-Variable -Name ErrCode -Scope Local -Force
Set-Variable -Name Executable -Scope Local -Force
Set-Variable -Name MSI -Scope Local -Force
Set-Variable -Name Parameters -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
Set-Variable -Name Switches -Scope Local -Force
$RelativePath = Get-RelativePath
$Global:ApplicationName = Get-MSIFileInfo -Path $global:MSI -Property 'ProductName'
$Global:ProductCode = Get-MSIFileInfo -Path $global:MSI -Property 'ProductCode'
If ((Test-Path -Path $RelativePath"Installer.log") -eq $true) {
Remove-Item -Path $RelativePath"Installer.log" -Force
}
$Executable = $Env:windir + "\system32\msiexec.exe"
$Switches = "/qb- /norestart"
$Parameters = "/x" + [char]32 + $Global:ProductCode + [char]32 + $Switches
$ErrCode = (Start-Process -FilePath $Executable -ArgumentList $Parameters -Wait -Passthru).ExitCode
Write-Host "Uninstalling"$Global:ApplicationName"....." -NoNewline
if (($ErrCode -eq 0) -or ($ErrCode -eq 3010)) {
Write-Host "Success" -ForegroundColor Yellow
} else {
Write-Host "Failed with error code "$ErrCode -ForegroundColor Red
}
$Notepad = $env:windir + "\notepad.exe"
$Parameters = $RelativePath + "UserInput.txt"
$ErrCode = (Start-Process -FilePath $Notepad -ArgumentList $Parameters -PassThru).ExitCode
$Switches = "/norestart"
$Parameters = "/i " + [char]34 + $Global:MSI + [char]34 + [char]32 + $Switches + [char]32 + "/lvx " + [char]34 + $RelativePath + "Installer.log" + [char]34
Write-Host $Parameters
Write-Host "Installing"$Global:ApplicationName"....." -NoNewline
$ErrCode = (Start-Process -FilePath $Executable -ArgumentList $Parameters -Wait -Passthru).ExitCode
if (($ErrCode -eq 0) -or ($ErrCode -eq 3010)) {
Write-Host "Success" -ForegroundColor Yellow
} else {
Write-Host "Failed with error code "$ErrCode -ForegroundColor Red
}
Write-Host "Creating Log File....." -NoNewline
If ((Test-Path $RelativePath"Installer.log") -eq $true) {
Write-Host "Success" -ForegroundColor Yellow
} else {
Write-Host "Failed" -ForegroundColor Red
}
#Cleanup Local Variables
Remove-Variable -Name ErrCode -Scope Local -Force
Remove-Variable -Name Executable -Scope Local -Force
Remove-Variable -Name MSI -Scope Local -Force
Remove-Variable -Name Parameters -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
Remove-Variable -Name Switches -Scope Local -Force
}
function Uninstall-MSI {
#Declare Local Variables
Set-Variable -Name ErrCode -Scope Local -Force
Set-Variable -Name Executable -Scope Local -Force
Set-Variable -Name Line -Scope Local -Force
Set-Variable -Name LogFile -Scope Local -Force
Set-Variable -Name MSI -Scope Local -Force
Set-Variable -Name Parameters -Scope Local -Force
Set-Variable -Name Process -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
Set-Variable -Name Switches -Scope Local -Force
$RelativePath = Get-RelativePath
$Process = Get-Process -Name notepad -ErrorAction SilentlyContinue
If ($Process -ne $null) {
Stop-Process -Name notepad -ErrorAction SilentlyContinue -Force
}
$Executable = $Env:windir + "\system32\msiexec.exe"
$Switches = "/qb- /norestart"
$Parameters = "/x" + [char]32 + $Global:ProductCode + [char]32 + $Switches
Write-Host "Uninstalling"$Global:ApplicationName"....." -NoNewline
$ErrCode = (Start-Process -FilePath $Executable -ArgumentList $Parameters -Wait -Passthru).ExitCode
if (($ErrCode -eq 0) -or ($ErrCode -eq 3010)) {
Write-Host "Success" -ForegroundColor Yellow
} else {
Write-Host "Failed with error code "$ErrCode -ForegroundColor Red
}
#Cleanup Local Variables
Remove-Variable -Name ErrCode -Scope Local -Force
Remove-Variable -Name Executable -Scope Local -Force
Remove-Variable -Name Line -Scope Local -Force
Remove-Variable -Name LogFile -Scope Local -Force
Remove-Variable -Name MSI -Scope Local -Force
Remove-Variable -Name Parameters -Scope Local -Force
Remove-Variable -Name Process -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
Remove-Variable -Name Switches -Scope Local -Force
}
function Get-ProductName {
#Declare Local Variables
Set-Variable -Name Database -Scope Local -Force
Set-Variable -Name MSIFileName -Scope Local -Force
Set-Variable -Name Output -Scope Local -Force
Set-Variable -Name OutputFile -Scope Local -Force
Set-Variable -Name PropertyName -Scope Local -Force
Set-Variable -Name PropertyValue -Scope Local -Force
Set-Variable -Name Record -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
Set-Variable -Name View -Scope Local -Force
Set-Variable -Name WindowsInstaller -Scope Local -Force
$RelativePath = Get-RelativePath
$MSIFileName = $global:MSI
$OutputFile = $RelativePath + "Report.txt"
$Output = [char]13
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "Product Name"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "------------"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$WindowsInstaller = New-Object -com WindowsInstaller.Installer
$Database = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $Null, $WindowsInstaller, @($MSIFileName, 0))
$View = $Database.GetType().InvokeMember("OpenView", "InvokeMethod", $Null, $Database, ("SELECT * FROM Property"))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $Null, $View, $Null)
while ($Record -ne $Null) {
$PropertyName = $Record.GetType().InvokeMember("StringData", "GetProperty", $Null, $Record, 1)
[string]$PropertyValue = $Record.GetType().InvokeMember("StringData", "GetProperty", $Null, $Record, 2)
IF ($PropertyName -like "*ProductName*") {
$Output = $PropertyValue
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
}
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $Null, $View, $Null)
}
#Cleanup Local Variables
Remove-Variable -Name Database -Scope Local -Force
Remove-Variable -Name MSIFileName -Scope Local -Force
Remove-Variable -Name Output -Scope Local -Force
Remove-Variable -Name OutputFile -Scope Local -Force
Remove-Variable -Name PropertyName -Scope Local -Force
Remove-Variable -Name PropertyValue -Scope Local -Force
Remove-Variable -Name Record -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
Remove-Variable -Name View -Scope Local -Force
Remove-Variable -Name WindowsInstaller -Scope Local -Force
}
function Get-ProductCode {
#Declare Local Variables
Set-Variable -Name Database -Scope Local -Force
Set-Variable -Name MSIFileName -Scope Local -Force
Set-Variable -Name Output -Scope Local -Force
Set-Variable -Name OutputFile -Scope Local -Force
Set-Variable -Name PropertyName -Scope Local -Force
Set-Variable -Name PropertyValue -Scope Local -Force
Set-Variable -Name Record -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
Set-Variable -Name View -Scope Local -Force
Set-Variable -Name WindowsInstaller -Scope Local -Force
$RelativePath = Get-RelativePath
$MSIFileName = $global:MSI
$OutputFile = $RelativePath + "Report.txt"
$Output = [char]13
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "Product Code"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "------------"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$WindowsInstaller = New-Object -com WindowsInstaller.Installer
$Database = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $Null, $WindowsInstaller, @($MSIFileName, 0))
$View = $Database.GetType().InvokeMember("OpenView", "InvokeMethod", $Null, $Database, ("SELECT * FROM Property"))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $Null, $View, $Null)
while ($Record -ne $Null) {
$PropertyName = $Record.GetType().InvokeMember("StringData", "GetProperty", $Null, $Record, 1)
[string]$PropertyValue = $Record.GetType().InvokeMember("StringData", "GetProperty", $Null, $Record, 2)
IF ($PropertyName -like "*ProductCode*") {
$Output = $PropertyValue
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
}
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $Null, $View, $Null)
}
#Cleanup Local Variables
Remove-Variable -Name Database -Scope Local -Force
Remove-Variable -Name MSIFileName -Scope Local -Force
Remove-Variable -Name Output -Scope Local -Force
Remove-Variable -Name OutputFile -Scope Local -Force
Remove-Variable -Name PropertyName -Scope Local -Force
Remove-Variable -Name PropertyValue -Scope Local -Force
Remove-Variable -Name Record -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
Remove-Variable -Name View -Scope Local -Force
Remove-Variable -Name WindowsInstaller -Scope Local -Force
}
function Get-MSIFileName {
#Declare Local Variables
Set-Variable -Name Output -Scope Local -Force
Set-Variable -Name OutputFile -Scope Local -Force
$OutputFile = $RelativePath + "Report.txt"
$Output = [char]13
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "MSI Filename"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "------------"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = $global:MSI
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
#Cleanup Local Variables
Remove-Variable -Name Output -Scope Local -Force
Remove-Variable -Name OutputFile -Scope Local -Force
}
function Get-Properties {
#Declare Local Variables
Set-Variable -Name Entries -Scope Local -Force
Set-Variable -Name Entry -Scope Local -Force
Set-Variable -Name File -Scope Local -Force
Set-Variable -Name FormattedEntry -Scope Local -Force
Set-Variable -Name Line -Scope Local -Force
Set-Variable -Name Output -Scope Local -Force
Set-Variable -Name OutputFile -Scope Local -Force
Set-Variable -Name Position -Scope Local -Force
Set-Variable -Name Property -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
Set-Variable -Name Value -Scope Local -Force
$OutputArray = @()
$RelativePath = Get-RelativePath
$File = Get-Content -Path $RelativePath"Installer.log"
$OutputFile = $RelativePath+"Report.txt"
$Entries = Get-Content -Path $RelativePath"UserInput.txt"
$Output = [char]13
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "Properties"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "----------"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
If ($Entries -ne $null) {
foreach ($Line in $File) {
If ($Line -like "*PROPERTY CHANGE: Adding*") {
foreach ($Entry in $Entries) {
$FormattedEntry = [char]42 + [char]39 + $Entry + [char]39 + [char]42
If ($Line -like $FormattedEntry) {
$Property = $Line
$Value = $Line
$Property = $Property.split(':')[-1]
If ($Property[0] -eq "\") {
$Property = $Line
$Property = $Property.split(':')[-2]
}
$Property = $Property.Trim()
$Property = $Property.Trim("Adding")
$Property = $Property.Trim()
$Property = $Property.Trim(" ")
$Position = $Property.IndexOf(" ")
If ($Property -notlike "*:\*") {
$Property = $Property.Substring(0, $Position)
}
$Output = $Property + ": " + $Entry
$OutputArray += $Output
}
}
}
}
$OutputArray = $OutputArray | select -Unique
$OutputArray = $OutputArray | Sort
foreach ($Item in $OutputArray) {
Write-Host $Item
If ($Item -ne $null) {
Out-File -FilePath $OutputFile -InputObject $Item -Append -Force
}
}
} else {
$Output = "No User Input Properties Exist"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
}
#Cleanup Local Variables
Remove-Variable -Name Entries -Scope Local -Force
Remove-Variable -Name Entry -Scope Local -Force
Remove-Variable -Name File -Scope Local -Force
Remove-Variable -Name FormattedEntry -Scope Local -Force
Remove-Variable -Name Line -Scope Local -Force
Remove-Variable -Name Output -Scope Local -Force
Remove-Variable -Name OutputFile -Scope Local -Force
Remove-Variable -Name Position -Scope Local -Force
Remove-Variable -Name Property -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
Remove-Variable -Name Value -Scope Local -Force
}
function Get-Features {
#Declare Local Variables
Set-Variable -Name Entries -Scope Local -Force
Set-Variable -Name File -Scope Local -Force
Set-Variable -Name Line -Scope Local -Force
Set-Variable -Name Output -Scope Local -Force
Set-Variable -Name OutputFile -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
Set-Variable -Name Value -Scope Local -Force
Set-Variable -Name Values -Scope Local -Force
$RelativePath = Get-RelativePath
$OutputFile = $RelativePath + "Report.txt"
$Entries = Get-Content -Path $RelativePath"UserInput.txt"
$Output = [char]13
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "Features"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "--------"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
If ($Entries -ne $null) {
$File = Get-Content -Path $global:RelativePath"Installer.log"
foreach ($Line in $File) {
If ($Line -like "*ADDLOCAL*") {
$Value = $Line.split(' ')[-1]
$Value = $Value -replace '''', ''
$Value = $Value.SubString(0, $Value.Length - 1)
$Values = $Value.Split(",")
foreach ($Value in $Values) {
Write-Host $Value
Out-File -FilePath $OutputFile -InputObject $Value -Append -Force
}
}
}
} else {
$Output = "No User Input Features Exist"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
}
#Cleanup Local Variables
Remove-Variable -Name Entries -Scope Local -Force
Remove-Variable -Name File -Scope Local -Force
Remove-Variable -Name Line -Scope Local -Force
Remove-Variable -Name Output -Scope Local -Force
Remove-Variable -Name OutputFile -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
Remove-Variable -Name Value -Scope Local -Force
Remove-Variable -Name Values -Scope Local -Force
}
function Get-Buttons {
#Declare Local Variables
Set-Variable -Name Database -Scope Local -Force
Set-Variable -Name Entries -Scope Local -Force
Set-Variable -Name Entry -Scope Local -Force
Set-Variable -Name MSIFileName -Scope Local -Force
Set-Variable -Name Output -Scope Local -Force
Set-Variable -Name OutputFile -Scope Local -Force
Set-Variable -Name PropertyName -Scope Local -Force
Set-Variable -Name PropertyValue -Scope Local -Force
Set-Variable -Name Record -Scope Local -Force
Set-Variable -Name RelativePath -Scope Local -Force
Set-Variable -Name View -Scope Local -Force
Set-Variable -Name WindowsInstaller -Scope Local -Force
$RelativePath = Get-RelativePath
$MSIFileName = $global:MSI
$Entries = Get-Content -Path $RelativePath"UserInput.txt"
$OutputFile = $RelativePath + "Report.txt"
$Output = [char]13
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "Buttons"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
$Output = "--------"
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
foreach ($Entry in $Entries) {
$WindowsInstaller = New-Object -com WindowsInstaller.Installer
$Database = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $Null, $WindowsInstaller, @($MSIFileName, 0))
$View = $Database.GetType().InvokeMember("OpenView", "InvokeMethod", $Null, $Database, ("SELECT * FROM RadioButton"))
$View.GetType().InvokeMember("Execute", "InvokeMethod", $Null, $View, $Null)
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $Null, $View, $Null)
$Entry = "*" + $Entry + "*"
while ($Record -ne $Null) {
$PropertyName = $Record.GetType().InvokeMember("StringData", "GetProperty", $Null, $Record, 1)
if (-not ($PropertyName -cmatch "[a-z]")) {
[string]$PropertyValue = $Record.GetType().InvokeMember("StringData", "GetProperty", $Null, $Record, 8)
IF ($PropertyValue -like $Entry) {
$Output = $PropertyName + " = " + $PropertyValue
Write-Host $Output
Out-File -FilePath $OutputFile -InputObject $Output -Append -Force
#Write-Host ($PropertyName + " = " + $PropertyValue)
}
}
$Record = $View.GetType().InvokeMember("Fetch", "InvokeMethod", $Null, $View, $Null)
}
}
#Cleanup Local Variables
Remove-Variable -Name Database -Scope Local -Force
Remove-Variable -Name Entries -Scope Local -Force
Remove-Variable -Name Entry -Scope Local -Force
Remove-Variable -Name MSIFileName -Scope Local -Force
Remove-Variable -Name Output -Scope Local -Force
Remove-Variable -Name OutputFile -Scope Local -Force
Remove-Variable -Name PropertyName -Scope Local -Force
Remove-Variable -Name PropertyValue -Scope Local -Force
Remove-Variable -Name Record -Scope Local -Force
Remove-Variable -Name RelativePath -Scope Local -Force
Remove-Variable -Name View -Scope Local -Force
Remove-Variable -Name WindowsInstaller -Scope Local -Force
}
Clear-Host
ProcessTextFiles
Get-MSIFile
New-UserInputFile
Install-MSI
Uninstall-MSI
Get-ProductName
Get-ProductCode
Get-MSIFileName
Get-Properties
Get-Features
Get-Buttons
#Cleanup Global Variables
Remove-Variable -Name ApplicationName -Scope Global -Force
Remove-Variable -Name MSI -Scope Global -Force
Remove-Variable -Name ProductCode -Scope Global -Force