-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInstall-SAP_Validation_Client.ps1
More file actions
253 lines (217 loc) · 7.83 KB
/
Install-SAP_Validation_Client.ps1
File metadata and controls
253 lines (217 loc) · 7.83 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
# 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."
$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."
}
}
}
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."
return 0
}else {
Write-Output "$ProgramName is not installed, attempting to install now."
}
}
}
return 1
}
# 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."
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
if (-not (Is-ProgramInstalled -ProgramName $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."
# 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 $ProgramName. Exit Code: $($process.ExitCode)"
return $false
}
} else {
Write-Output "Skipping $ProgramName installation as it is already installed."
return $true
}
}
# Function to install .NET Framework 4.8
function Install-DotNet48 {
param (
[string]$InstallerPath
)
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."
return 0
} else {
Write-Output "Failed to install .NET Framework 4.8. Exit Code: $($process.ExitCode)"
return 1
}
} else {
Write-Output "Skipping .NET Framework 4.8 installation as it is already installed."
return 0
}
}
Start-Transcript -OutputDirectory "$env:ProgramData\TurnerLogs\SAP_Validation_Client_Transcript.txt"
$ProgramList = @(
@{
Name = 'Microsoft Visual C++ 2013 Redistributable';
Installed = $False;
},
@{
Name = 'Microsoft Visual C++ 2015-2019 Redistributable';
Installed = $False;
},
@{
Name = 'Microsoft .NET Runtime';
Installed = $False;
},
@{
Name = #SAP .Net Connector;
Installed = $False;
},
@{
Name = #SAP SCE 7.5;
Installed = $False;
},
@{
Name = #SAP Validation Client
Installed = $False;
}
)
Check-InitialIsProgramInstalled -ProgramList ([ref]$ProgramList)
# List of programs to install with paths, validation paths and validation file names
$MicrosoftVC = @(
@{
Name = 'Microsoft Visual C++ 2013 Redistributable';
Path = '.\1-VC++2013\12.0.40664.0\VC2013-Install.cmd';
},
@{
Name = 'Microsoft Visual C++ 2015-2019 Redistributable';
Path = '.\2-VC++2015\14.38.33135.0\InstallVC.cmd';
}
)
# .NET Framework 4.8 installer - Not being validated
$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';
}
# Uninstall Validation Client Path - Not being validated
$sapnetConnector = @{
Name = 'SAP .NET Connector';
Path = '.\5-SAP .Net Connector\Connector\install-sapconnector.cmd';
}
# Loop through and install each Visual C++ Redistributable
foreach ($VC in $MicrosoftVC) {
$result = Install-Program -ProgramName $VC.Name -InstallerPath $VC.Path
if (-not $result){
Write-Output "Stopping further installations due to failure in installing $($VC.Name)."
exit 1
}
else{
Write-Output "$($VC.name) Installed correctly, returning code 0."
return 0
}
}
# Install .NET Framework 4.8
$dotNetResult = Install-DotNet48 -InstallerPath $dotNetInstaller.Path
if (-not $dotNetResult) {
Write-Output "Stopping further installations due to failure in installing .NET Framework 4.8."
exit 1
}
else{
Write-Output "$($VC.name) Installed correctly, returning code 0."
return 0
}
# Uninstall Validation Client
$ValCLientResult = Install-Program -ProgramName $UninstallValClient.Name -InstallerPath $UninstallValClient.Path
if(-not $result){
Write-Output "Stopping further installations due to failure in uninstalling $($UninstallValClient.Name)"
exit 1
}
else{
Write-Output "$($UninstallValClient.Name) Installed Correctly, returning code 0."
return 0
}
# Install SAP .Net Connector
$sapnetconnectorResult = Install-Program -ProgramName $sapnetConnector.Name -InstallerPath $sapnetConnector.Path
if(-not $result){
Write-Output "Stopping further installations due to failure in uninstalling $($sapnetConnector.Name)"
exit 1
}
else{
Write-Output "$($sapnetConnector.Name) Installed Correctly, returning code 0."
return 0
}
# Install SAP SCE 7.5
# Install SAP Validation Client
Write-Output "All programs installed successfully."
Stop-Transcript