400 lines
6.7 KiB
PowerShell
Executable File
400 lines
6.7 KiB
PowerShell
Executable File
############################################################
|
||
# PART 7.1
|
||
#
|
||
# Veeam LogManager
|
||
############################################################
|
||
|
||
function Copy-VeeamSetupLogs {
|
||
|
||
Write-Log "Sichere Veeam Setup Logs"
|
||
|
||
$Source = "C:\ProgramData\Veeam\Setup\Temp"
|
||
|
||
$Destination = Join-Path `
|
||
$LogDir `
|
||
"VeeamSetup"
|
||
|
||
if(!(Test-Path $Source))
|
||
{
|
||
Write-Log "Keine Setup Logs gefunden."
|
||
|
||
return
|
||
}
|
||
|
||
if(Test-Path $Destination)
|
||
{
|
||
Remove-Item `
|
||
$Destination `
|
||
-Recurse `
|
||
-Force
|
||
}
|
||
|
||
Copy-Item `
|
||
$Source `
|
||
$Destination `
|
||
-Recurse `
|
||
-Force
|
||
|
||
Write-Log "Setup Logs kopiert."
|
||
|
||
}
|
||
############################################################
|
||
# PART 7.2
|
||
#
|
||
# Part 7.2 – Logdatei suchen
|
||
############################################################
|
||
|
||
function Get-LatestSetupLog {
|
||
|
||
$Folder = Join-Path `
|
||
$LogDir `
|
||
"VeeamSetup"
|
||
|
||
if(!(Test-Path $Folder))
|
||
{
|
||
return $null
|
||
}
|
||
|
||
Get-ChildItem `
|
||
$Folder `
|
||
-Recurse `
|
||
-Filter *.log |
|
||
Sort-Object LastWriteTime -Descending |
|
||
Select-Object -First 1
|
||
|
||
}
|
||
############################################################
|
||
# PART 7.3#
|
||
#
|
||
# Part 7.3 – Logdatei analysieren
|
||
############################################################
|
||
|
||
function Analyze-VeeamLog {
|
||
|
||
param(
|
||
|
||
[string]$LogFile
|
||
|
||
)
|
||
|
||
if(!(Test-Path $LogFile))
|
||
{
|
||
|
||
Write-Log "Keine Logdatei vorhanden."
|
||
|
||
return
|
||
|
||
}
|
||
|
||
Write-Log "Analysiere Logdatei"
|
||
|
||
$Content = Get-Content `
|
||
$LogFile `
|
||
-ErrorAction SilentlyContinue
|
||
|
||
foreach($Line in $Content)
|
||
{
|
||
|
||
if($Line -match "SQL")
|
||
{
|
||
Write-Log "SQL Hinweis: $Line"
|
||
}
|
||
|
||
if($Line -match "Access denied")
|
||
{
|
||
Write-Log "Berechtigungsproblem: $Line"
|
||
}
|
||
|
||
if($Line -match "Return value 3")
|
||
{
|
||
Write-Log "MSI Fehler erkannt."
|
||
}
|
||
|
||
if($Line -match "failed")
|
||
{
|
||
Write-Log $Line
|
||
}
|
||
|
||
if($Line -match "Exception")
|
||
{
|
||
Write-Log $Line
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
############################################################
|
||
# PART 7.4
|
||
#
|
||
# PART 7.4 – ExitCode analysieren
|
||
############################################################
|
||
|
||
function Analyze-ExitCode {
|
||
|
||
param(
|
||
|
||
[int]$ExitCode
|
||
|
||
)
|
||
|
||
Write-Log "Installer ExitCode : $ExitCode"
|
||
|
||
switch($ExitCode)
|
||
{
|
||
|
||
0
|
||
{
|
||
Write-Log "Installation erfolgreich."
|
||
}
|
||
|
||
3010
|
||
{
|
||
Write-Log "Neustart erforderlich."
|
||
}
|
||
|
||
1603
|
||
{
|
||
|
||
Write-Log "Fatal Error"
|
||
|
||
Copy-VeeamSetupLogs
|
||
|
||
$Log = Get-LatestSetupLog
|
||
|
||
if($Log)
|
||
{
|
||
|
||
Analyze-VeeamLog `
|
||
$Log.FullName
|
||
|
||
}
|
||
|
||
}
|
||
|
||
default
|
||
{
|
||
|
||
Write-Log "Unbekannter ExitCode"
|
||
|
||
Copy-VeeamSetupLogs
|
||
|
||
}
|
||
|
||
}
|
||
|
||
}
|
||
############################################################
|
||
# PART 7.5
|
||
#
|
||
# PART 7.5 – Veeam Dienste prüfen
|
||
############################################################
|
||
|
||
function Test-VeeamServices {
|
||
|
||
Write-Log "Prüfe Veeam Dienste"
|
||
|
||
$Services = @(
|
||
|
||
"VeeamBackupSvc",
|
||
|
||
"VeeamBrokerSvc",
|
||
|
||
"VeeamMountSvc"
|
||
|
||
)
|
||
|
||
foreach($Service in $Services)
|
||
{
|
||
|
||
$S = Get-Service `
|
||
$Service `
|
||
-ErrorAction SilentlyContinue
|
||
|
||
if(!$S)
|
||
{
|
||
|
||
Write-Log "$Service nicht installiert."
|
||
|
||
continue
|
||
|
||
}
|
||
|
||
Write-Log "$($S.Name) : $($S.Status)"
|
||
|
||
}
|
||
|
||
}
|
||
############################################################
|
||
# PART 7.6
|
||
#
|
||
# PART 7.6 – Version prüfen
|
||
############################################################
|
||
|
||
function Get-VeeamVersion {
|
||
|
||
$Exe =
|
||
Join-Path `
|
||
$InstallPath `
|
||
"Backup\Veeam.Backup.Service.exe"
|
||
|
||
if(Test-Path $Exe)
|
||
{
|
||
|
||
$Version =
|
||
(Get-Item $Exe).VersionInfo.ProductVersion
|
||
|
||
Write-Log "Veeam Version : $Version"
|
||
|
||
}
|
||
|
||
}
|
||
############################################################
|
||
# PART 7.7
|
||
#
|
||
# Veeam Installation Engine
|
||
############################################################
|
||
|
||
function Install-Veeam {
|
||
|
||
Write-Log "======================================="
|
||
Write-Log "Starte Veeam Installation"
|
||
Write-Log "======================================="
|
||
|
||
$Arguments = @(
|
||
"/AnswerFile"
|
||
"`"$AnswerFile`""
|
||
"/SkipNetworkLogonErrors"
|
||
)
|
||
|
||
$StartTime = Get-Date
|
||
|
||
Write-Log "Installationsbeginn : $StartTime"
|
||
|
||
try {
|
||
|
||
$Process = Start-Process `
|
||
-FilePath $VeeamInstaller `
|
||
-ArgumentList $Arguments `
|
||
-PassThru
|
||
|
||
}
|
||
catch {
|
||
|
||
Stop-Installation "Installer konnte nicht gestartet werden.`n$($_.Exception.Message)"
|
||
|
||
}
|
||
|
||
Write-Log "PID : $($Process.Id)"
|
||
|
||
while(!$Process.HasExited)
|
||
{
|
||
|
||
Write-Host "." -NoNewline
|
||
|
||
Start-Sleep 10
|
||
|
||
$Process.Refresh()
|
||
|
||
}
|
||
|
||
Write-Host ""
|
||
|
||
$EndTime = Get-Date
|
||
|
||
$Duration = New-TimeSpan `
|
||
-Start $StartTime `
|
||
-End $EndTime
|
||
|
||
Write-Log "Installationsende : $EndTime"
|
||
|
||
Write-Log ("Dauer : {0:hh\:mm\:ss}" -f $Duration)
|
||
|
||
Analyze-ExitCode $Process.ExitCode
|
||
|
||
if($Process.ExitCode -eq 0 -or
|
||
$Process.ExitCode -eq 3010)
|
||
{
|
||
|
||
Test-VeeamServices
|
||
|
||
Get-VeeamVersion
|
||
|
||
}
|
||
|
||
}
|
||
############################################################
|
||
# PART 7.8
|
||
#
|
||
# PART 7.8 – Installationsreport
|
||
############################################################
|
||
|
||
function Show-InstallationSummary {
|
||
|
||
Write-Host ""
|
||
Write-Host "============================================="
|
||
Write-Host "Installation abgeschlossen"
|
||
Write-Host "============================================="
|
||
Write-Host ""
|
||
|
||
Write-Host "Computer"
|
||
|
||
Write-Host "--------"
|
||
|
||
Write-Host $env:COMPUTERNAME
|
||
|
||
Write-Host ""
|
||
|
||
Write-Host "SQL"
|
||
|
||
Write-Host "----"
|
||
|
||
Write-Host $SQLConnection
|
||
|
||
Write-Host ""
|
||
|
||
Write-Host "Installation"
|
||
|
||
Write-Host "-------------"
|
||
|
||
Write-Host $InstallPath
|
||
|
||
Write-Host ""
|
||
|
||
Write-Host "Catalog"
|
||
|
||
Write-Host "-------"
|
||
|
||
Write-Host $CatalogPath
|
||
|
||
Write-Host ""
|
||
|
||
Write-Host "IR Cache"
|
||
|
||
Write-Host "--------"
|
||
|
||
Write-Host $IRCachePath
|
||
|
||
Write-Host ""
|
||
|
||
Write-Host "Log"
|
||
|
||
Write-Host "---"
|
||
|
||
Write-Host "$LogDir\Install.log"
|
||
|
||
}
|
||
############################################################
|
||
# MAIN
|
||
#
|
||
# PART 7.9 – Gesamtablauf
|
||
############################################################
|
||
|
||
Invoke-SystemCheck
|
||
|
||
Invoke-Prerequisites
|
||
|
||
Initialize-AnswerFile
|
||
|
||
Install-Veeam
|
||
|
||
Show-InstallationSummary |