Files
syno-scripts/VEEAM-INSTALL/Modules/Veeam/VeeamInstallation.psm1
T
2026-08-10 22:10:17 +02:00

1400 lines
19 KiB
PowerShell

<#
---------------------------------------------------------------------------
Module......: VeeamInstallation.psm1
Projekt.....: Veeam Enterprise Installer
Version.....: 2.0.0
Beschreibung:
Veeam Backup & Replication Installation
Ziel:
Veeam Backup & Replication 13.0.1.1071
Funktionen:
- Installationsquelle prüfen
- Version erkennen
- Setup vorbereiten
- Silent Installation
- Installation prüfen
- Dienste prüfen
---------------------------------------------------------------------------#>
Set-StrictMode -Version Latest
#region Variablen
$Script:VeeamModuleVersion = "2.0.0"
$Script:ExpectedVersion =
"13.0.1.1071"
#endregion
############################################################
# Get-VeeamInstallationPath
############################################################
function Get-VeeamInstallationPath {
<#
.SYNOPSIS
Ermittelt Veeam Installationspfad.
#>
$Paths = @(
"C:\Program Files\Veeam\Backup and Replication",
"C:\Program Files (x86)\Veeam\Backup and Replication"
)
foreach($Path in $Paths)
{
if(Test-Path $Path)
{
return $Path
}
}
return $null
}
############################################################
# Test-VeeamInstalled
############################################################
function Test-VeeamInstalled {
<#
.SYNOPSIS
Prüft ob Veeam installiert ist.
#>
$Path =
Get-VeeamInstallationPath
return (
$null -ne $Path
)
}
############################################################
# Get-VeeamServices
############################################################
function Get-VeeamServices {
<#
.SYNOPSIS
Liefert Veeam Dienste.
#>
Get-Service |
Where-Object {
$_.Name -like "Veeam*"
}
}
#Beginn PART 2
############################################################
# Get-VeeamSetupFile
############################################################
function Get-VeeamSetupFile {
<#
.SYNOPSIS
Sucht Veeam Installationsdatei.
#>
param(
[Parameter(Mandatory)]
[string]$SourcePath
)
if(!(Test-Path $SourcePath))
{
throw `
"Installationsquelle nicht gefunden: $SourcePath"
}
if(Test-Path -Path $SourcePath -PathType Leaf)
{
if([IO.Path]::GetExtension($SourcePath) -ne ".exe")
{
throw "Die Installationsdatei muss eine EXE-Datei sein: $SourcePath"
}
return (Resolve-Path -Path $SourcePath).Path
}
$Files = Get-ChildItem `
-Path $SourcePath `
-Recurse `
-Filter "Veeam.Silent.Install.exe" `
-File `
-ErrorAction SilentlyContinue
$Setup = $Files | Select-Object -First 1
if($null -ne $Setup)
{
return $Setup.FullName
}
return $null
}
############################################################
# Test-VeeamSource
############################################################
function Test-VeeamSource {
<#
.SYNOPSIS
Prüft Installationsquelle.
#>
param(
[Parameter(Mandatory)]
[string]$SourcePath
)
$Setup =
Get-VeeamSetupFile `
-SourcePath $SourcePath
[PSCustomObject]@{
Source =
$SourcePath
SetupFound =
($null -ne $Setup)
SetupFile =
$Setup
}
}
############################################################
# Get-VeeamRegistryInformation
############################################################
function Get-VeeamRegistryInformation {
<#
.SYNOPSIS
Liest Veeam Registry Informationen.
#>
$Paths = @(
"HKLM:\SOFTWARE\Veeam",
"HKLM:\SOFTWARE\WOW6432Node\Veeam"
)
foreach($Path in $Paths)
{
if(Test-Path $Path)
{
Get-ItemProperty `
$Path
}
}
}
############################################################
# Get-VeeamVersion
############################################################
function Get-VeeamVersion {
<#
.SYNOPSIS
Ermittelt installierte Version.
#>
$Software =
Get-ChildItem `
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" `
-ErrorAction SilentlyContinue
foreach($Entry in $Software)
{
$Data =
Get-ItemProperty `
$Entry.PSPath
$DisplayName = $Data.PSObject.Properties["DisplayName"]
$DisplayVersion = $Data.PSObject.Properties["DisplayVersion"]
if(
$null -ne $DisplayName -and
$DisplayName.Value -like "*Veeam Backup & Replication*"
)
{
if($null -ne $DisplayVersion)
{
return $DisplayVersion.Value
}
}
}
return $null
}
#Beginn PART 3
############################################################
# New-VeeamInstallParameter
############################################################
function New-VeeamInstallParameter {
<#
.SYNOPSIS
Erstellt Installationsparameter.
#>
param(
[Parameter(Mandatory)]
[string]$AnswerFile,
[string]$LogFolder,
[switch]$SkipNetworkLogonErrors
)
$Parameters = @()
if(!(Test-Path -Path $AnswerFile -PathType Leaf))
{
throw "Veeam-Antwortdatei nicht gefunden: $AnswerFile"
}
$Parameters += "/AnswerFile"
$Parameters += ('"{0}"' -f $AnswerFile)
if(![string]::IsNullOrWhiteSpace($LogFolder))
{
$Parameters += "/LogFolder"
$Parameters += ('"{0}"' -f $LogFolder)
}
if($SkipNetworkLogonErrors)
{
$Parameters += "/SkipNetworkLogonErrors"
}
return $Parameters
}
############################################################
# Get-VeeamInstallLogPath
############################################################
function Get-VeeamInstallLogPath {
<#
.SYNOPSIS
Erstellt Installationslog Pfad.
#>
param(
[string]$BasePath =
"C:\ProgramData\VeeamInstaller\Logs"
)
if(!(Test-Path $BasePath))
{
New-Item `
-Path $BasePath `
-ItemType Directory `
-Force |
Out-Null
}
return (
Join-Path $BasePath ("VeeamInstall_" +
(
Get-Date -Format "yyyyMMdd_HHmmss"
) +
".log"
)
)
}
############################################################
# Start-VeeamSetup
############################################################
function Start-VeeamSetup {
<#
.SYNOPSIS
Startet Veeam Setup.
#>
param(
[Parameter(Mandatory)]
[string]$SetupFile,
[string[]]$Arguments
)
if(!(Test-Path -Path $SetupFile -PathType Leaf))
{
throw `
"Setup Datei nicht gefunden: $SetupFile"
}
$LogFile =
Get-VeeamInstallLogPath
$Process =
Start-Process `
-FilePath $SetupFile `
-ArgumentList $Arguments `
-Wait `
-PassThru `
-RedirectStandardOutput $LogFile `
-ErrorAction Stop
return [PSCustomObject]@{
ExitCode =
$Process.ExitCode
Successful =
($Process.ExitCode -in @(0, 1, 2, 12, 13, 14, 3010, 3011))
RebootRequired =
($Process.ExitCode -in @(12, 13, 3010))
LogFile =
$LogFile
}
}
#Beginn PART 4
############################################################
# Test-VeeamServices
############################################################
function Test-VeeamServices {
<#
.SYNOPSIS
Prüft Veeam Dienste.
#>
$Services =
Get-VeeamServices
$Result = @()
foreach($Service in $Services)
{
$Result += [PSCustomObject]@{
Name =
$Service.Name
Status =
$Service.Status
Running =
(
$Service.Status -eq "Running"
)
}
}
return $Result
}
############################################################
# Test-VeeamVersion
############################################################
function Test-VeeamVersion {
<#
.SYNOPSIS
Prüft Veeam Version.
#>
$Installed =
Get-VeeamVersion
if($null -eq $Installed)
{
return $false
}
return (
$Installed -eq
$Script:ExpectedVersion
)
}
############################################################
# Get-VeeamComponents
############################################################
function Get-VeeamComponents {
<#
.SYNOPSIS
Listet installierte Komponenten.
#>
return @(
Get-VeeamServices |
ForEach-Object {
[PSCustomObject]@{
Component = $_.DisplayName
Service = $_.Name
Installed = $true
Running = ($_.Status -eq "Running")
}
}
)
}
############################################################
# Test-VeeamInstallation
############################################################
function Test-VeeamInstallation {
<#
.SYNOPSIS
Gesamte Installationsprüfung.
#>
[PSCustomObject]@{
Installed =
Test-VeeamInstalled
Version =
Get-VeeamVersion
VersionOK =
Test-VeeamVersion
Services =
Test-VeeamServices
Components =
Get-VeeamComponents
Time =
Get-Date
}
}
#Beginn PART 5
############################################################
# Start-VeeamServices
############################################################
function Start-VeeamServices {
<#
.SYNOPSIS
Startet alle Veeam Dienste.
#>
$Services =
Get-VeeamServices
foreach($Service in $Services)
{
if(
$Service.Status -ne "Running"
)
{
Start-Service `
-Name $Service.Name `
-ErrorAction SilentlyContinue
}
}
return $true
}
############################################################
# Stop-VeeamServices
############################################################
function Stop-VeeamServices {
<#
.SYNOPSIS
Stoppt alle Veeam Dienste.
#>
$Services =
Get-VeeamServices
foreach($Service in $Services)
{
if(
$Service.Status -eq "Running"
)
{
Stop-Service `
-Name $Service.Name `
-Force `
-ErrorAction SilentlyContinue
}
}
return $true
}
############################################################
# Test-VeeamSQLConfiguration
############################################################
function Test-VeeamSQLConfiguration {
<#
.SYNOPSIS
Prüft Veeam SQL Einstellungen.
#>
param(
[string]$SQLServer =
$env:COMPUTERNAME,
[string]$Instance =
"VEEAMSQLSERVER",
[string]$Database =
"VeeamBackup"
)
[PSCustomObject]@{
Server =
$SQLServer
Instance =
$Instance
Connection =
Test-SQLConnection `
-Server $SQLServer `
-Instance $Instance
Database =
$Database
DatabaseExists =
Test-DatabaseExists `
-DatabaseName $Database `
-Server $SQLServer `
-Instance $Instance
Time =
Get-Date
}
}
############################################################
# Test-VeeamLicense
############################################################
function Test-VeeamLicense {
<#
.SYNOPSIS
Prüft Lizenzdatei.
#>
param(
[string]$LicenseFile
)
if(
[string]::IsNullOrWhiteSpace(
$LicenseFile
)
)
{
return [PSCustomObject]@{
Found = $false
Message =
"Keine Lizenzdatei angegeben."
}
}
[PSCustomObject]@{
Found =
(
Test-Path $LicenseFile
)
File =
$LicenseFile
}
}
############################################################
# Complete-VeeamInstallation
############################################################
function Complete-VeeamInstallation {
<#
.SYNOPSIS
Abschlussprüfung.
#>
Start-VeeamServices
return (
Test-VeeamInstallation
)
}
#Beginn PART 6
############################################################
# Initialize-VeeamInstallation
############################################################
function Initialize-VeeamInstallation {
<#
.SYNOPSIS
Bereitet Installation vor.
#>
param(
[string]$InstallPath =
"C:\ProgramData\VeeamInstaller"
)
if(!(Test-Path $InstallPath))
{
New-Item `
-Path $InstallPath `
-ItemType Directory `
-Force |
Out-Null
}
[PSCustomObject]@{
Path =
$InstallPath
Created =
$true
Time =
Get-Date
}
}
############################################################
# Invoke-VeeamInstallation
############################################################
function Invoke-VeeamInstallation {
<#
.SYNOPSIS
Führt komplette Installation aus.
#>
param(
[Parameter(Mandatory)]
[string]$SourcePath,
[Parameter(Mandatory)]
[string]$AnswerFile,
[string]$LogFolder,
[switch]$SkipNetworkLogonErrors
)
$Preparation =
Initialize-VeeamInstallation
$Setup =
Get-VeeamSetupFile `
-SourcePath $SourcePath
if($null -eq $Setup)
{
throw `
"Kein Veeam Setup gefunden."
}
$Arguments =
New-VeeamInstallParameter `
-AnswerFile $AnswerFile `
-LogFolder $LogFolder `
-SkipNetworkLogonErrors:$SkipNetworkLogonErrors
$Result =
Start-VeeamSetup `
-SetupFile $Setup `
-Arguments $Arguments
return [PSCustomObject]@{
Preparation =
$Preparation
Setup =
$Setup
Result =
$Result
}
}
############################################################
# Rollback-VeeamInstallation
############################################################
function Rollback-VeeamInstallation {
<#
.SYNOPSIS
Bereitet Rollback vor.
#>
Stop-VeeamServices
[PSCustomObject]@{
Action =
"Rollback vorbereitet"
Time =
Get-Date
}
}
############################################################
# Repair-VeeamInstallation
############################################################
function Repair-VeeamInstallation {
<#
.SYNOPSIS
Reparaturprüfung.
#>
$Report =
Test-VeeamInstallation
if(
!$Report.Installed
)
{
return $false
}
Start-VeeamServices
return $true
}
#Beginn PART 7
############################################################
# Get-VeeamInstallationReport
############################################################
function Get-VeeamInstallationReport {
<#
.SYNOPSIS
Erstellt Installationsbericht.
#>
[PSCustomObject]@{
Computer =
$env:COMPUTERNAME
Installed =
Test-VeeamInstalled
Version =
Get-VeeamVersion
ExpectedVersion =
$Script:ExpectedVersion
VersionOK =
Test-VeeamVersion
Services =
Test-VeeamServices
SQL =
Test-VeeamSQLConfiguration
Time =
Get-Date
}
}
############################################################
# Get-VeeamModuleInformation
############################################################
function Get-VeeamModuleInformation {
<#
.SYNOPSIS
Liefert Modulstatus.
#>
[PSCustomObject]@{
Module =
"VeeamInstallation.psm1"
Version =
$Script:VeeamModuleVersion
TargetVersion =
$Script:ExpectedVersion
Loaded =
$true
}
}
############################################################
# Test-VeeamEnvironment
############################################################
function Test-VeeamEnvironment
{
<#
.SYNOPSIS
Prüft Voraussetzungen.
#>
[PSCustomObject]@{
OS =
(Get-CimInstance Win32_OperatingSystem).Caption
Architecture = $env:PROCESSOR_ARCHITECTURE
Administrator =
(
([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()
).IsInRole(
[Security.Principal.WindowsBuiltInRole]::Administrator
)
)
SQLExpected = "VEEAMSQLSERVER"
Time = Get-Date
}
}
#Beginn PART 8
############################################################
# Export Module Functions
############################################################
Export-ModuleMember `
-Function `
Get-VeeamInstallationPath,
Test-VeeamInstalled,
Get-VeeamServices,
Get-VeeamSetupFile,
Test-VeeamSource,
Get-VeeamRegistryInformation,
Get-VeeamVersion,
New-VeeamInstallParameter,
Get-VeeamInstallLogPath,
Start-VeeamSetup,
Test-VeeamServices,
Test-VeeamVersion,
Get-VeeamComponents,
Test-VeeamInstallation,
Start-VeeamServices,
Stop-VeeamServices,
Test-VeeamSQLConfiguration,
Test-VeeamLicense,
Complete-VeeamInstallation,
Initialize-VeeamInstallation,
Invoke-VeeamInstallation,
Rollback-VeeamInstallation,
Repair-VeeamInstallation,
Get-VeeamInstallationReport,
Get-VeeamModuleInformation,
Test-VeeamEnvironment
############################################################
# Ende VeeamInstallation.psm1
############################################################