-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInstall-SAP_Validation_Client_2.ps1
More file actions
340 lines (296 loc) · 11.5 KB
/
Copy pathInstall-SAP_Validation_Client_2.ps1
File metadata and controls
340 lines (296 loc) · 11.5 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
# Function to check if a specific program is installed by searching the registry
function Check-InitialIsProgramInstalled {
param (
[ref]$ProgramList
)
# Define registry paths for installed programs
$registryPaths = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall',
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall'
)
# Loop through each program in the list
foreach ($program in $ProgramList.value) {
$found = $False
# Check each registry path for the program
foreach ($path in $registryPaths) {
$keys = Get-ChildItem -Path $path -ErrorAction SilentlyContinue
foreach ($key in $keys) {
$displayName = (Get-ItemProperty -Path $key.PSPath -Name DisplayName -ErrorAction SilentlyContinue).DisplayName
if ($displayName -like "*$($program.Name)*") {
Write-Output "$($program.Name) is installed. Updating array value to skip install. <Check-InitialisProgramInstalled>`n"
$program.Installed = $True
$found = $True
break
}
}
if ($found) { break } # Stop searching if program is found
}
if (-not $found) {
Write-Output "$($program.Name) is not installed. Will attempt to install. <Check-InitialisProgramInstalled>`n"
}
}
Write-output "Checked all Programs, Moving on.`n"
$ProgramList.value
"`n"
}
<# function Is-ProgramInstalled {
param (
[string]$ProgramName
)
$registryPaths = @(
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall',
'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall'
)
foreach ($path in $registryPaths) {
$keys = Get-ChildItem -Path $path -ErrorAction SilentlyContinue
foreach ($key in $keys) {
$displayName = (Get-ItemProperty -Path $key.PSPath -Name DisplayName -ErrorAction SilentlyContinue).DisplayName
if ($displayName -like "*$ProgramName*") {
Write-Output "$ProgramName is already installed. <Is-ProgramInstalled>`n"
}else {
Write-Output "$ProgramName is not installed, attempting to install now. <Is-ProgramInstalled>`n"
}
}
}
} #>
# Function to check for .NET Framework 4.8 installation
function Is-DotNet48Installed {
$regKey = 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'
$release = (Get-ItemProperty -Path $regKey).Release
if ($release -ge 533320) {
Write-Output ".NET Framework 4.8 is already installed. <Is-DotNet48Installed>`n"
return 0
}
return 1
}
# Function to install a program
function Install-Program {
param (
[string]$ProgramName,
[string]$InstallerPath,
[ref]$ProgramList
)
# Check if the program is already installed
"Checking for $ProgramName"
if (-not ($ProgramName)) {
Write-Output "Installing $ProgramName..."
$process = Start-Process -FilePath $InstallerPath -Wait -PassThru
# Check if installation was successful
if ($process.ExitCode -eq 0) {
Write-Output "$ProgramName installed successfully. <Install-Program>`n"
# Update the "Installed" flag in the $ProgramList array
foreach ($program in $ProgramList.Value) {
if ($program.Name -eq $ProgramName) {
$program.Installed = $True
Write-Output "$ProgramName installation status updated in the list. <Install-Program>`n"
}
}
return $true
} else {
Write-Output "Failed to install $ProgramName. Exit Code: $($process.ExitCode) <Install-Program>`n"
return $false
}
} else {
Write-Output "Skipping $ProgramName installation as it is already installed. <Install-Program>`n"
return $true
}
}
# Function to check for .NET Framework 4.8 installation
function Is-DotNet48Installed {
$regKey = 'HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full'
$release = (Get-ItemProperty -Path $regKey -ErrorAction SilentlyContinue).Release
if ($release -ge 533320) {
Write-Output ".NET Framework 4.8 is already installed. <Is-DotNet48Installed>`n"
}
return $false
}
# Function to install .NET Framework 4.8
function Install-DotNet48 {
param (
[string]$InstallerPath,
[ref]$ProgramList,
[string]$ProgramName
)
if (-not (Is-DotNet48Installed)) {
Write-Output "Installing .NET Framework 4.8..."
$process = Start-Process -FilePath $InstallerPath -Wait -PassThru
if ($process.ExitCode -eq 0) {
Write-Output ".NET Framework 4.8 installed successfully. <Install-DotNet48>`n"
# Update the "Installed" flag in the $ProgramList array
foreach ($program in $ProgramList.Value) {
if ($program.Name -eq $ProgramName) {
$program.Installed = $True
Write-Output "$ProgramName installation status updated in the list."
}
}
return $true
} else {
Write-Output "Failed to install .NET Framework 4.8. Exit Code: $($process.ExitCode) <Install-DotNet48>`n"
return 1
}
} else {
Write-Output "Skipping .NET Framework 4.8 installation as it is already installed. <Install-DotNet48>`n"
}
}
# Update the call to Install-DotNet48 with the new parameters
$dotNetResult = Install-DotNet48 -InstallerPath $dotNetInstaller.Path -ProgramList ([ref]$ProgramList) -ProgramName $dotNetInstaller.Name
# Start logging the transcript
Start-Transcript -Path "$env:ProgramData\TurnerLogs\SAP_Validation_Client_Transcript.txt"
# List of programs to check installation status
$ProgramList = @(
@{
Name = 'Microsoft Visual C++ 2013 Redistributable (x64)';
Installed = $False;
},
@{
Name = 'Microsoft Visual C++ 2013 Redistributable (x86)';
Installed = $False;
},
@{
Name = 'Microsoft Visual C++ 2015-2022 Redistributable (x64)';
Installed = $False;
},
@{
Name = 'Microsoft Visual C++ 2015-2022 Redistributable (x86)';
Installed = $False;
},
@{
Name = 'Microsoft .NET Runtime';
Installed = $False;
},
@{
Name = 'SAP .Net Connector 3.0 for .NET 4.0 on x86';
Installed = $False;
},
@{
Name = 'Validation for SAP Solutions CE 23.2';
Installed = $False;
},
@{
Name = 'SCE for SAP Solutions 22.2 Patch 37';
Installed = $False;
}
)
# Check if the programs are already installed
Check-InitialIsProgramInstalled -ProgramList ([ref]$ProgramList)
"Check Initial Program Installed is done Moving on To Microsoft VC`n"
# List of programs with installation paths
$MicrosoftVC = @(
@{
Name = 'Microsoft Visual C++ 2013 Redistributable (x64)';
Path = '.\1-VC++2013\12.0.40664.0\VC2013-Install.cmd';
},
@{
Name = 'Microsoft Visual C++ 2013 Redistributable (x86)';
Path = '.\1-VC++2013\12.0.40664.0\VC2013-Install.cmd';
},
@{
Name = 'Microsoft Visual C++ 2015-2022 Redistributable (x64)';
Path = '.\2-VC++2015\14.38.33135.0\InstallVC.cmd';
},
@{
Name = 'Microsoft Visual C++ 2015-2022 Redistributable (x86)';
Path = '.\2-VC++2015\14.38.33135.0\InstallVC.cmd';
}
)
# .NET Framework 4.8 installer
$dotNetInstaller = @{
Name = 'Microsoft .NET Runtime';
Path = '.\3-.Net 4.8\.Net Framework 4.8\load_netframework_64.cmd';
}
# Uninstall Validation Client Path - Not being validated
$UninstallValClient = @{
Name = 'Uninstall Validation Client';
Path = '.\4-Uninstall Validation Client\Uninstall\SAP_Validation_Client_Prereq_Removal.cmd';
}
# SAP .NET Connector Path
$sapnetConnector = @{
Name = 'SAP .NET Connector';
Path = '.\5-SAP .Net Connector\Connector\install-sapconnector.cmd';
}
#SAP Validation Client Path
$sapValidationClient = @{
Name = 'SAP Validation Client';
Path = ".\6-SAP Validation Client\Validation Client\install-sapvalidation232.cmd"
}
#SAP SCE Path
$sapSCE = @{
Name = 'SAP SCE';
Path = ".\7-SAP SCE 7.5\SCE\install-sapvalidationsce.cmd"
}
# Loop through and install each Visual C++ Redistributable if needed
foreach ($VC in $MicrosoftVC) {
$program = $ProgramList | Where-Object {$_.Name -eq $VC.Name}
if (-not $Program.Installed) {
$result = Install-Program -ProgramName $VC.Name -InstallerPath $VC.Path -ProgramList ([ref]$ProgramList)
if (-not $result) {
Write-Output "Stopping further installations due to failure in installing $($VC.Name)."
}
}else{
Write-output "$($VC.Name) is installed, skipping install."
}
}
# Install .NET Framework 4.8 if needed
$dotNetResult = Install-DotNet48 -InstallerPath $dotNetInstaller.Path
if (-not $dotNetResult) {
Write-Output "Stopping further installations due to failure in installing .NET Framework 4.8."
return 1
}
else{
Write-Output "$($dotNetInstaller.name) Installed correctly, returning code 0. <dotNetResult>"
}
# Example for Uninstall Validation Client
$ValClientResult = Install-Program -ProgramName $UninstallValClient.Name -InstallerPath $UninstallValClient.Path -ProgramList ([ref]$ProgramList)
if (-not $ValClientResult) { # Changed from $result to $ValClientResult
Write-Output "Stopping further installations due to failure in uninstalling $($UninstallValClient.Name)"
return 1
} else {
Write-Output "$($UninstallValClient.Name) Installed Correctly, returning code 0."
}
# Install SAP .Net Connector
$sapnetconnectorResult = Install-Program -ProgramName $sapnetConnector.Name -InstallerPath $sapnetConnector.Path -ProgramList ([ref]$ProgramList)
if(-not $result){
Write-Output "Stopping further installations due to failure in uninstalling $($sapnetConnector.Name)"
return 1
}
else{
Write-Output "$($sapnetConnector.Name) Installed Correctly, returning code 0."
}
# Install SAP Validation Client
$sapValidationClientResult = Install-Program -ProgramName $sapValidationClient.Name -InstallerPath $sapValidationClient.Path -ProgramList ([ref]$ProgramList)
if(-not $result){
Write-Output "Stopping further installations due to failure in uninstalling $($sapValidationClient.Name)"
return 1
}
else{
Write-Output "$($sapValidationClient.Name) Installed Correctly, returning code 0."
}
# Install SAP SCE 7.5
$sapsceResult = Install-Program -ProgramName $sapSCE.Name -InstallerPath $sapSCE.Path -ProgramList ([ref]$ProgramList)
if(-not $result){
Write-Output "Stopping further installations due to failure in uninstalling $($sapSCE.Name)"
return 1
}
else{
Write-Output "$($sapSCE.Name) Installed Correctly, returning code 0."
}
$Success = $True
$NotInstalled = @()
foreach ($Program in $ProgramList) {
if ($Program.Installed -ne $True) {
$NotInstalled += $Program.Name
$Success = $False
}
}
if (-not $Success) {
Write-Output "`nThe following programs are not installed:"
$NotInstalled | ForEach-Object { Write-Output $_ }
return 1
} else {
Write-Output "All programs are installed. Check succeeded."
return 0
}
# Stop logging the transcript
Stop-Transcript