Initialer Import der Synology Scripts

This commit is contained in:
root
2026-08-05 08:43:57 +02:00
commit 5e32a7c411
404 changed files with 79932 additions and 0 deletions
+247
View File
@@ -0,0 +1,247 @@
#Requires -RunAsAdministrator
<#
===========================================================================
Veeam Backup & Replication v13 Enterprise Installer
Version : 2.0
Author : ChatGPT + Benutzer
Part 1
===========================================================================
Enthält:
- Grundeinstellungen
- Konfiguration
- Logging
- Fehlerbehandlung
- Arbeitsverzeichnisse
- Initialisierung
===========================================================================
#>
$ErrorActionPreference = "Stop"
############################################################
# VERSION
############################################################
$Script:Version = "2.0"
############################################################
# VERZEICHNISSE
############################################################
$Script:WorkDir = "C:\Temp\VeeamInstall"
$Script:LogDir = Join-Path $WorkDir "Logs"
$Script:StateFile = Join-Path $WorkDir "State.json"
$Script:ResumeFlag = Join-Path $WorkDir "Resume.flag"
$Script:InstallLog = Join-Path $LogDir "Install.log"
############################################################
# INSTALLATIONSQUELLEN
############################################################
$Script:DVDSource = "E:\"
$Script:NetworkSource = "\\172.68.1.1\Sources"
############################################################
# SQL
############################################################
$Script:SQLInstance = "VEEAMSQLSERVER"
$Script:DatabaseName = "VeeamBackup"
$Script:SQLAuthentication = 0
############################################################
# INSTALLATIONSPFADE
############################################################
$Script:InstallPath = "F:\Program Files\Veeam\Backup and Replication"
$Script:CatalogPath = "H:\VBRCatalog"
$Script:IRCachePath = "F:\ProgramData\Veeam\Backup\IRCache"
############################################################
# PORTS
############################################################
$Script:GuestCatalogPort = 9393
$Script:VeeamServicePort = 9392
$Script:SecureConnectionPort = 9401
$Script:RestServicePort = 9419
############################################################
# OPTIONEN
############################################################
$Script:AutoReboot = $true
$Script:UseLicense = $false
$Script:UseServiceAccount = $false
############################################################
# PLUGINS
############################################################
$Script:Plugins = @{
AHV_INSTALL = 0
KVM_INSTALL = 0
PVE_INSTALL = 0
SCP_INSTALL = 0
AWS_INSTALL = 0
AZURE_INSTALL = 0
GCP_INSTALL = 0
KASTEN_INSTALL = 0
}
############################################################
# LOGGING
############################################################
function Write-Log {
param(
[Parameter(Mandatory)]
[string]$Message
)
$Time = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$Line = "$Time - $Message"
Write-Host $Line
Add-Content `
-Path $InstallLog `
-Value $Line
}
############################################################
# FEHLER
############################################################
function Stop-Installation {
param(
[string]$Message
)
Write-Log ""
Write-Log "########################################"
Write-Log "INSTALLATION ABGEBROCHEN"
Write-Log $Message
Write-Log "########################################"
exit 1
}
############################################################
# VERZEICHNISSE
############################################################
function Initialize-Directories {
if(Test-Path $WorkDir)
{
Remove-Item `
$WorkDir `
-Recurse `
-Force
}
New-Item `
-ItemType Directory `
-Path $WorkDir `
-Force | Out-Null
New-Item `
-ItemType Directory `
-Path $LogDir `
-Force | Out-Null
}
############################################################
# STARTBANNER
############################################################
function Show-Banner {
Clear-Host
Write-Host ""
Write-Host "==============================================="
Write-Host " Veeam Backup & Replication v13"
Write-Host " Enterprise Installer"
Write-Host ""
Write-Host " Version $Version"
Write-Host "==============================================="
Write-Host ""
}
############################################################
# INITIALISIERUNG
############################################################
function Initialize-Installer {
Show-Banner
Initialize-Directories
Write-Log "======================================="
Write-Log "Installer Version $Version"
Write-Log "Computer: $env:COMPUTERNAME"
Write-Log "Benutzer: $env:USERNAME"
Write-Log "======================================="
}
+346
View File
@@ -0,0 +1,346 @@
############################################################
# PART 2
#
# Resume Manager
# Statusverwaltung
# Pending Reboot
# Registry Funktionen
############################################################
############################################################
# REGISTRY
############################################################
function Test-RegistryValue {
param(
[string]$Path,
[string]$Name
)
try{
Get-ItemProperty `
-Path $Path `
-Name $Name `
-ErrorAction Stop | Out-Null
return $true
}
catch{
return $false
}
}
function Get-RegistryValue {
param(
[string]$Path,
[string]$Name
)
try{
(Get-ItemProperty `
-Path $Path `
-Name $Name `
-ErrorAction Stop).$Name
}
catch{
return $null
}
}
############################################################
# STATUSDATEI
############################################################
function Save-State {
param(
[string]$Step
)
$State = [PSCustomObject]@{
Version = $Version
Computer = $env:COMPUTERNAME
Date = Get-Date
Step = $Step
}
$State |
ConvertTo-Json |
Set-Content `
-Path $StateFile `
-Encoding UTF8
Write-Log "Status gespeichert ($Step)"
}
############################################################
function Load-State {
if(!(Test-Path $StateFile))
{
return $null
}
try{
Get-Content `
$StateFile `
-Raw |
ConvertFrom-Json
}
catch{
return $null
}
}
############################################################
function Remove-State {
if(Test-Path $StateFile)
{
Remove-Item `
$StateFile `
-Force
Write-Log "Statusdatei entfernt"
}
}
############################################################
# RESUME FLAG
############################################################
function Set-ResumeFlag {
New-Item `
-ItemType File `
-Path $ResumeFlag `
-Force |
Out-Null
Write-Log "Resume Flag gesetzt"
}
############################################################
function Clear-ResumeFlag {
if(Test-Path $ResumeFlag)
{
Remove-Item `
$ResumeFlag `
-Force
Write-Log "Resume Flag entfernt"
}
}
############################################################
# PENDING REBOOT
############################################################
function Test-PendingReboot {
Write-Log "Prüfe Pending Reboot"
$Pending = $false
if(Test-Path `
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending")
{
$Pending = $true
}
if(Test-Path `
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired")
{
$Pending = $true
}
if(Test-RegistryValue `
"HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" `
"PendingFileRenameOperations")
{
$Pending = $true
}
if($Pending)
{
Write-Log "Neustart erforderlich"
}
else
{
Write-Log "Kein Neustart erforderlich"
}
return $Pending
}
############################################################
# SCHEDULED TASK
############################################################
function Register-ResumeTask {
Write-Log "Erstelle Resume Task"
$Action = New-ScheduledTaskAction `
-Execute "powershell.exe" `
-Argument "-ExecutionPolicy Bypass -File `"$PSCommandPath`" -Resume"
$Trigger = New-ScheduledTaskTrigger `
-AtStartup
Register-ScheduledTask `
-TaskName "VeeamInstallerResume" `
-Action $Action `
-Trigger $Trigger `
-RunLevel Highest `
-Force |
Out-Null
}
############################################################
function Remove-ResumeTask {
if(Get-ScheduledTask `
-TaskName "VeeamInstallerResume" `
-ErrorAction SilentlyContinue)
{
Unregister-ScheduledTask `
-TaskName "VeeamInstallerResume" `
-Confirm:$false
Write-Log "Resume Task entfernt"
}
}
############################################################
# RESTART
############################################################
function Restart-AndResume {
Write-Log "Automatischer Neustart"
Save-State `
-Step "Resume"
Set-ResumeFlag
Register-ResumeTask
Restart-Computer `
-Force
exit
}
############################################################
# RESUME
############################################################
function Resume-Installation {
if(!(Test-Path $ResumeFlag))
{
return
}
Write-Log "Installation wird fortgesetzt"
$State = Load-State
if($null -eq $State)
{
Stop-Installation "Statusdatei beschädigt."
}
Remove-ResumeTask
Clear-ResumeFlag
Remove-State
Write-Log "Fortsetzung abgeschlossen"
}
############################################################
# STARTPARAMETER
############################################################
param(
[switch]$Resume
)
if($Resume)
{
Resume-Installation
}
+282
View File
@@ -0,0 +1,282 @@
############################################################
# PART 3
#
# Installationsquelle
# Lizenz
# SQL Prüfung
############################################################
############################################################
# INSTALLATIONSQUELLE
############################################################
function Select-InstallationSource {
Write-Host ""
Write-Host "Veeam Installationsquelle"
Write-Host "========================="
Write-Host "1 = DVD / ISO ($DVDSource)"
Write-Host "2 = Netzwerk ($NetworkSource)"
Write-Host ""
do {
$Choice = Read-Host "Quelle auswählen"
} until ($Choice -in @("1","2"))
switch($Choice)
{
"1"
{
$Script:VeeamSource = $DVDSource
}
"2"
{
Connect-NetworkSource
}
}
Write-Log "Installationsquelle: $VeeamSource"
}
############################################################
function Connect-NetworkSource {
Write-Log "Verbinde Netzwerkquelle"
$Credential = Get-Credential
if(Get-PSDrive VEEAMSRC -ErrorAction SilentlyContinue)
{
Remove-PSDrive VEEAMSRC -Force
}
New-PSDrive `
-Name VEEAMSRC `
-PSProvider FileSystem `
-Root $NetworkSource `
-Credential $Credential `
-ErrorAction Stop |
Out-Null
$Script:VeeamSource = "VEEAMSRC:\"
}
############################################################
# INSTALLER
############################################################
function Find-VeeamInstaller {
$Script:VeeamInstaller = Join-Path `
$VeeamSource `
"Setup\Silent\Veeam.Silent.Install.exe"
if(!(Test-Path $VeeamInstaller))
{
Stop-Installation "Veeam Installer wurde nicht gefunden."
}
Write-Log "Installer gefunden"
}
############################################################
# ANSWER FILE
############################################################
function Find-AnswerFile {
$Script:AnswerFileSource = Join-Path `
$VeeamSource `
"Setup\Silent\AnswerFiles\VBR\VbrAnswerFile_install.xml"
if(!(Test-Path $AnswerFileSource))
{
Stop-Installation "Antwortdatei wurde nicht gefunden."
}
Write-Log "Antwortdatei gefunden"
}
############################################################
# LIZENZ
############################################################
function Find-LicenseFile {
$Script:LicenseSource = Join-Path `
$VeeamSource `
"License\veeam.lic"
$Script:LicenseTarget = Join-Path `
$WorkDir `
"veeam.lic"
if(Test-Path $LicenseSource)
{
Copy-Item `
$LicenseSource `
$LicenseTarget `
-Force
$Script:UseLicense = $true
Write-Log "Lizenz gefunden"
}
else
{
$Script:UseLicense = $false
Write-Log "Community Edition"
}
}
############################################################
# SQL
############################################################
function Initialize-SQL {
$Script:SQLServer = $env:COMPUTERNAME
$Script:SQLConnection = "$SQLServer\$SQLInstance"
}
############################################################
function Test-SQLService {
Write-Log "Prüfe SQL Dienst"
$ServiceName = "MSSQL`$$SQLInstance"
$Service = Get-Service `
-Name $ServiceName `
-ErrorAction SilentlyContinue
if(!$Service)
{
Stop-Installation `
"SQL Instanz '$SQLInstance' wurde nicht gefunden."
}
if($Service.Status -ne "Running")
{
Stop-Installation `
"SQL Dienst läuft nicht."
}
Write-Log "SQL Dienst OK"
}
############################################################
function Test-SQLConnectivity {
Write-Log "Prüfe SQL Verbindung"
try{
Add-Type -AssemblyName System.Data
$Connection = New-Object `
System.Data.SqlClient.SqlConnection
$Connection.ConnectionString =
"Server=$SQLConnection;" +
"Integrated Security=True;" +
"Connection Timeout=5;"
$Connection.Open()
$Connection.Close()
Write-Log "SQL Verbindung erfolgreich"
}
catch{
Stop-Installation `
"Keine Verbindung zu $SQLConnection möglich.`n$($_.Exception.Message)"
}
}
############################################################
# VEEAM BEREITS INSTALLIERT?
############################################################
function Test-VeeamInstalled {
Write-Log "Prüfe vorhandene Installation"
$Service = Get-Service `
-Name "VeeamBackupSvc" `
-ErrorAction SilentlyContinue
if($Service)
{
Stop-Installation `
"Veeam Backup & Replication ist bereits installiert."
}
Write-Log "Keine vorhandene Installation"
}
############################################################
# GESAMTPRÜFUNG
############################################################
function Initialize-InstallationSource {
Select-InstallationSource
Find-VeeamInstaller
Find-AnswerFile
Find-LicenseFile
Initialize-SQL
Test-SQLService
Test-SQLConnectivity
Test-VeeamInstalled
}
+471
View File
@@ -0,0 +1,471 @@
############################################################
# PART 4.1
#
# PART 4.1 Betriebssystem prüfen
############################################################
function Test-OperatingSystem {
Write-Log "Prüfe Betriebssystem"
try {
$OS = Get-CimInstance Win32_OperatingSystem
}
catch {
Stop-Installation "Betriebssystem konnte nicht ermittelt werden."
}
Write-Log "Betriebssystem : $($OS.Caption)"
Write-Log "Version : $($OS.Version)"
Write-Log "Build : $($OS.BuildNumber)"
if($OS.ProductType -ne 3)
{
Stop-Installation "Dieses Script unterstützt nur Windows Server."
}
switch -Regex ($OS.Caption)
{
"2022"
{
Write-Log "Windows Server 2022 erkannt."
}
"2025"
{
Write-Log "Windows Server 2025 erkannt."
}
default
{
Stop-Installation "Nicht unterstütztes Betriebssystem."
}
}
}
############################################################
# PART 4.2
#
# PART 4.2 PowerShell-Version prüfen
############################################################
function Test-PowerShellVersion {
Write-Log "Prüfe PowerShell"
$PSVersion = $PSVersionTable.PSVersion
Write-Log "PowerShell Version: $PSVersion"
if($PSVersion.Major -lt 5)
{
Stop-Installation "PowerShell 5.1 oder höher wird benötigt."
}
if($PSVersion.Major -ge 7)
{
Write-Log "PowerShell 7 erkannt."
}
else
{
Write-Log "PowerShell 5.x erkannt."
}
}
############################################################
# PART 4.3
#
# PART 4.3 CPU prüfen
############################################################
function Test-CPU {
Write-Log "Prüfe CPU"
$CPU = Get-CimInstance Win32_Processor
Write-Log "CPU : $($CPU.Name)"
Write-Log "Kerne : $($CPU.NumberOfCores)"
Write-Log "Logische CPUs : $($CPU.NumberOfLogicalProcessors)"
if($CPU.NumberOfLogicalProcessors -lt 2)
{
Stop-Installation "Mindestens 2 logische Prozessoren erforderlich."
}
}
############################################################
# PART 4.4
#
# PART 4.4 RAM prüfen
############################################################
function Test-Memory {
Write-Log "Prüfe Arbeitsspeicher"
$RAM = (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory
$RAMGB = [Math]::Round($RAM / 1GB,2)
Write-Log "RAM : $RAMGB GB"
if($RAMGB -lt 8)
{
Stop-Installation "Mindestens 8 GB RAM erforderlich."
}
}
############################################################
# PART 4.5
#
# PART 4.5 Laufwerke prüfen
############################################################
function Test-Drive {
param(
[Parameter(Mandatory)]
[string]$DriveLetter,
[Parameter(Mandatory)]
[int]$MinimumFreeGB
)
Write-Log "Prüfe Laufwerk $DriveLetter"
$Drive = Get-CimInstance Win32_LogicalDisk |
Where-Object DeviceID -eq $DriveLetter
if(!$Drive)
{
Stop-Installation "Laufwerk $DriveLetter existiert nicht."
}
$Free = [Math]::Round($Drive.FreeSpace / 1GB,2)
Write-Log "Freier Speicher : $Free GB"
if($Free -lt $MinimumFreeGB)
{
Stop-Installation "Zu wenig Speicher auf $DriveLetter."
}
}
############################################################
# PART 4.6
#
# PART 4.6 Installationspfade prüfen
############################################################
function Test-InstallationPaths {
Write-Log "Prüfe Installationslaufwerke"
Test-Drive "C:" 10
Test-Drive "F:" 20
Test-Drive "H:" 20
}
############################################################
# PART 4.7
#
# PART 4.7 Pending Reboot
############################################################
function Test-PendingReboot {
Write-Log "Prüfe Pending Reboot"
$Pending = $false
if(Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending")
{
$Pending = $true
}
if(Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired")
{
$Pending = $true
}
if(Get-ItemProperty `
"HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" `
-ErrorAction SilentlyContinue |
Select-Object -ExpandProperty PendingFileRenameOperations `
-ErrorAction SilentlyContinue)
{
$Pending = $true
}
if($Pending)
{
Write-Log "Pending Reboot erkannt."
Restart-AndResume
}
Write-Log "Kein Pending Reboot."
}
############################################################
# PART 4.8
#
# PART 4.8 Gesamter Systemcheck
############################################################
function Invoke-SystemCheck {
Write-Log ""
Write-Log "===================================="
Write-Log "Systemprüfung gestartet"
Write-Log "===================================="
Test-OperatingSystem
Test-PowerShellVersion
Test-CPU
Test-Memory
Test-InstallationPaths
Test-PendingReboot
Write-Log "Systemprüfung erfolgreich abgeschlossen."
}
############################################################
# PART 4.9
#
# SQL Server Prüfung
#
# SQL Server 2022 Standard
# Instanz VEEAMSQLSERVER
############################################################
function Test-SQLInstance {
Write-Log "===================================="
Write-Log "Prüfe SQL Instanz"
Write-Log "===================================="
#
# Variablen
#
$SQLInstanceName = "VEEAMSQLSERVER"
$SQLServerName = $env:COMPUTERNAME
$SQLConnection = "$SQLServerName\$SQLInstanceName"
Write-Log "SQL Server : $SQLConnection"
#
# SQL Dienst prüfen
#
$ServiceName = "MSSQL`$$SQLInstanceName"
$SQLService = Get-Service `
-Name $ServiceName `
-ErrorAction SilentlyContinue
if(!$SQLService)
{
Stop-Installation `
"SQL Instanz $SQLInstanceName wurde nicht gefunden."
}
Write-Log "SQL Dienst gefunden"
Write-Log "Status: $($SQLService.Status)"
if($SQLService.Status -ne "Running")
{
Stop-Installation `
"SQL Dienst läuft nicht."
}
#
# SQL Verbindung testen
#
Write-Log "Teste SQL Verbindung"
try
{
Add-Type -AssemblyName System.Data
$ConnectionString = @"
Server=$SQLConnection;
Integrated Security=True;
Database=master;
Connection Timeout=10;
"@
$Connection = New-Object `
System.Data.SqlClient.SqlConnection
$Connection.ConnectionString =
$ConnectionString
$Connection.Open()
Write-Log "SQL Verbindung erfolgreich"
#
# SQL Version lesen
#
$Command = $Connection.CreateCommand()
$Command.CommandText =
"SELECT SERVERPROPERTY('ProductVersion'),
SERVERPROPERTY('Edition'),
SERVERPROPERTY('ProductLevel')"
$Reader = $Command.ExecuteReader()
while($Reader.Read())
{
$SQLVersion = $Reader.GetValue(0)
$SQLEdition = $Reader.GetValue(1)
$SQLLevel = $Reader.GetValue(2)
Write-Log "SQL Version : $SQLVersion"
Write-Log "Edition : $SQLEdition"
Write-Log "Level : $SQLLevel"
}
$Reader.Close()
#
# Datenbank prüfen
#
$Command = $Connection.CreateCommand()
$Command.CommandText =
@"
SELECT name
FROM sys.databases
WHERE name='VeeamBackup'
"@
$Result = $Command.ExecuteScalar()
if($Result)
{
Write-Log "VeeamBackup Datenbank vorhanden"
}
else
{
Write-Log "VeeamBackup Datenbank wird durch Veeam Setup erstellt"
}
#
# Login Rechte prüfen
#
$Command.CommandText =
@"
SELECT IS_SRVROLEMEMBER('sysadmin')
"@
$SysAdmin =
$Command.ExecuteScalar()
if($SysAdmin -eq 1)
{
Write-Log "Installationskonto besitzt SQL Sysadmin Rechte"
}
else
{
Write-Log "WARNUNG: Konto besitzt keine SQL Sysadmin Rolle"
}
$Connection.Close()
}
catch
{
Stop-Installation `
"SQL Verbindung fehlgeschlagen:`n$($_.Exception.Message)"
}
Write-Log "SQL Prüfung erfolgreich"
}
+205
View File
@@ -0,0 +1,205 @@
############################################################
# PART 5.1
#
# Part 5.1 .NET Framework prüfen
############################################################
function Test-DotNetFramework {
Write-Log "Prüfe .NET Framework"
$RegPath = "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"
if(!(Test-Path $RegPath))
{
Stop-Installation ".NET Framework wurde nicht gefunden."
}
$Release = (Get-ItemProperty $RegPath).Release
Write-Log ".NET Release : $Release"
if($Release -lt 528040)
{
Stop-Installation ".NET Framework 4.8 oder höher wird benötigt."
}
Write-Log ".NET Framework OK"
}
############################################################
# PART 5.2
#
# Part 5.2 Visual C++ Redistributables prüfen
############################################################
function Test-VisualCRedistributables {
Write-Log "Prüfe Visual C++ Redistributables"
$VC = Get-ItemProperty `
HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*,
HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* `
-ErrorAction SilentlyContinue |
Where-Object {
$_.DisplayName -like "*Microsoft Visual C++*"
}
if(!$VC)
{
Write-Log "Keine Visual C++ Redistributables gefunden."
Write-Log "Werden während der Veeam Installation installiert."
return
}
foreach($Item in $VC)
{
Write-Log "$($Item.DisplayName) $($Item.DisplayVersion)"
}
}
############################################################
# PART 5.3
#
# Part 5.3 Installationspfade vorbereiten
############################################################
function Initialize-InstallDirectories {
Write-Log "Erstelle Installationsverzeichnisse"
$Folders = @(
$InstallPath,
$CatalogPath,
$IRCachePath
)
foreach($Folder in $Folders)
{
if(!(Test-Path $Folder))
{
New-Item `
-ItemType Directory `
-Path $Folder `
-Force |
Out-Null
Write-Log "Ordner erstellt: $Folder"
}
else
{
Write-Log "Ordner vorhanden: $Folder"
}
}
}
############################################################
# PART 5.4
#
# Part 5.4 Schreibtest
############################################################
function Test-WritePermissions {
Write-Log "Prüfe Schreibrechte"
foreach($Folder in @($InstallPath,$CatalogPath,$IRCachePath))
{
$TestFile = Join-Path $Folder "WriteTest.tmp"
try
{
"TEST" | Set-Content $TestFile
Remove-Item $TestFile -Force
Write-Log "$Folder beschreibbar."
}
catch
{
Stop-Installation "Keine Schreibrechte auf $Folder."
}
}
}
############################################################
# PART 5.5
#
# Part 5.5 Ports prüfen
############################################################
function Test-Ports {
Write-Log "Prüfe benötigte Ports"
$Ports = @(
$VeeamServicePort,
$GuestCatalogPort,
$SecureConnectionPort,
$RestServicePort
)
foreach($Port in $Ports)
{
$Connection = Get-NetTCPConnection `
-State Listen `
-ErrorAction SilentlyContinue |
Where-Object LocalPort -eq $Port
if($Connection)
{
Write-Log "WARNUNG: Port $Port ist bereits belegt."
}
else
{
Write-Log "Port $Port verfügbar."
}
}
}
############################################################
# PART 5.6
#
# Part 5.6 Windows Firewall prüfen
############################################################
function Test-Firewall {
Write-Log "Prüfe Windows Firewall"
$Profiles = Get-NetFirewallProfile
foreach($Profile in $Profiles)
{
Write-Log "$($Profile.Name): Enabled=$($Profile.Enabled)"
}
}
############################################################
# PART 5.7
#
# Part 5.7 Voraussetzungen prüfen
############################################################
function Invoke-Prerequisites {
Write-Log ""
Write-Log "===================================="
Write-Log "Prüfung der Voraussetzungen"
Write-Log "===================================="
Test-DotNetFramework
Test-VisualCRedistributables
Initialize-InstallDirectories
Test-WritePermissions
Test-Ports
Test-Firewall
Write-Log "Voraussetzungen erfolgreich geprüft."
}
+220
View File
@@ -0,0 +1,220 @@
############################################################
# PART 6.1
#
# AnswerFile kopieren
############################################################
function Copy-AnswerFile {
Write-Log "Kopiere Antwortdatei"
$Script:AnswerFile = Join-Path `
$WorkDir `
"VbrAnswerFile_install.xml"
if(Test-Path $AnswerFile)
{
Remove-Item `
$AnswerFile `
-Force
}
Copy-Item `
-Path $AnswerFileSource `
-Destination $AnswerFile `
-Force
if(!(Test-Path $AnswerFile))
{
Stop-Installation "Antwortdatei konnte nicht kopiert werden."
}
attrib -R $AnswerFile
Write-Log "Antwortdatei erfolgreich kopiert"
}
############################################################
# PART 6.2
#
# Part 6.2 XML laden
############################################################
function Open-AnswerFile {
Write-Log "Lade XML"
try
{
[xml]$Script:AnswerXML =
Get-Content `
$AnswerFile `
-Encoding UTF8
}
catch
{
Stop-Installation "XML konnte nicht geladen werden."
}
}
############################################################
# PART 6.3
#
# Part 6.3 XML-Eigenschaft setzen
############################################################
function Set-VBRProperty {
param(
[Parameter(Mandatory)]
[string]$Name,
[Parameter(Mandatory)]
[string]$Value
)
$Node = $AnswerXML.
unattendedInstallationConfiguration.
properties.
property |
Where-Object Name -eq $Name
if(!$Node)
{
Write-Log "XML Property $Name nicht gefunden."
return
}
$Node.value = $Value
Write-Log "$Name = $Value"
}
############################################################
# PART 6.4
#
# Part 6.4 XML konfigurieren
############################################################
function Set-AnswerFileConfiguration {
Write-Log "Konfiguriere XML"
Set-VBRProperty "ACCEPT_EULA" "1"
Set-VBRProperty "ACCEPT_LICENSING_POLICY" "1"
Set-VBRProperty "ACCEPT_THIRDPARTY_LICENSES" "1"
Set-VBRProperty "ACCEPT_REQUIRED_SOFTWARE" "1"
if($UseLicense)
{
Set-VBRProperty "VBR_LICENSE_FILE" $LicenseTarget
}
else
{
Set-VBRProperty "VBR_LICENSE_FILE" "0"
}
Set-VBRProperty "VBR_SQLSERVER_INSTALL" "0"
Set-VBRProperty "VBR_SQLSERVER_ENGINE" "0"
Set-VBRProperty "VBR_SQLSERVER_SERVER" $SQLConnection
Set-VBRProperty "VBR_SQLSERVER_DATABASE" $DatabaseName
Set-VBRProperty "VBR_SQLSERVER_AUTHENTICATION" "0"
Set-VBRProperty "VBR_ENTRAID_DATABASE_INSTALL" "0"
Set-VBRProperty "INSTALLDIR" $InstallPath
Set-VBRProperty "VM_CATALOGPATH" $CatalogPath
Set-VBRProperty "VBR_IRCACHE" $IRCachePath
Set-VBRProperty "VBRC_SERVICE_PORT" $GuestCatalogPort
Set-VBRProperty "VBR_SERVICE_PORT" $VeeamServicePort
Set-VBRProperty "VBR_SECURE_CONNECTIONS_PORT" $SecureConnectionPort
Set-VBRProperty "VBR_RESTSERVICE_PORT" $RestServicePort
Set-VBRProperty "REBOOT_IF_REQUIRED" "$RebootRequired"
foreach($Plugin in $Plugins.Keys)
{
Set-VBRProperty `
$Plugin `
"$($Plugins[$Plugin])"
}
}
############################################################
# PART 6.5
#
# Part 6.5 XML validieren
############################################################
function Test-AnswerFile {
Write-Log "Prüfe XML"
if(!$AnswerXML.unattendedInstallationConfiguration)
{
Stop-Installation "Ungültige XML."
}
if(!$AnswerXML.unattendedInstallationConfiguration.properties)
{
Stop-Installation "XML Properties fehlen."
}
Write-Log "XML erfolgreich geprüft."
}
############################################################
# PART 6.6
#
# Part 6.6 XML speichern
############################################################
function Save-AnswerFile {
Write-Log "Speichere XML"
try
{
$Writer = New-Object System.Xml.XmlTextWriter(
$AnswerFile,
[System.Text.Encoding]::UTF8
)
$Writer.Formatting = "Indented"
$AnswerXML.Save($Writer)
$Writer.Close()
Write-Log "Antwortdatei gespeichert"
}
catch
{
Stop-Installation "Antwortdatei konnte nicht gespeichert werden.`n$($_.Exception.Message)"
}
}
############################################################
# PART 6.7
#
# Part 6.7 Gesamtablauf
############################################################
function Initialize-AnswerFile {
Copy-AnswerFile
Open-AnswerFile
Set-AnswerFileConfiguration
Test-AnswerFile
Save-AnswerFile
}
+400
View File
@@ -0,0 +1,400 @@
############################################################
# 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
+184
View File
@@ -0,0 +1,184 @@
############################################################
# Transcript
#
# PART 8.1 Enterprise Transcript Logging
############################################################
$TranscriptFile = Join-Path `
$LogDir `
"PowerShell_Transcript.log"
############################################################
# Start Transcript
############################################################
function Start-TranscriptLogging {
Write-Log "Starte PowerShell Transcript"
try {
if(Test-Path $TranscriptFile)
{
Remove-Item `
$TranscriptFile `
-Force
}
Start-Transcript `
-Path $TranscriptFile `
-Append `
-ErrorAction Stop
Write-Log "Transcript gestartet"
}
catch {
Write-Log "Transcript konnte nicht gestartet werden."
}
}
############################################################
# Stop Transcript
############################################################
function Stop-TranscriptLogging {
Write-Log "Beende Transcript"
try {
Stop-Transcript | Out-Null
}
catch {
}
}
############################################################
# JSON laden
############################################################
function Import-Configuration {
param(
[string]$ConfigurationFile
)
Write-Log "Lade Konfiguration"
if(!(Test-Path $ConfigurationFile))
{
Stop-Installation `
"Konfigurationsdatei nicht gefunden."
}
try
{
$Script:Config =
Get-Content `
$ConfigurationFile `
-Raw |
ConvertFrom-Json
}
catch
{
Stop-Installation `
"JSON konnte nicht gelesen werden."
}
Write-Log "Konfiguration geladen"
}
############################################################
# Werte übernehmen
############################################################
function Initialize-Configuration {
Write-Log "Übernehme Konfiguration"
$DVDSource =
$Config.General.DVDSource
$NetworkSource =
$Config.General.NetworkSource
$SQLInstanceName =
$Config.SQL.Instance
$DatabaseName =
$Config.SQL.Database
$SQLAuthentication =
$Config.SQL.Authentication
$InstallPath =
$Config.Paths.InstallPath
$CatalogPath =
$Config.Paths.CatalogPath
$IRCachePath =
$Config.Paths.IRCache
$GuestCatalogPort =
$Config.Ports.Catalog
$VeeamServicePort =
$Config.Ports.Service
$SecureConnectionPort =
$Config.Ports.Secure
$RestServicePort =
$Config.Ports.REST
}
############################################################
# Plugins
############################################################
$Plugins = @{
AHV_INSTALL =
[int]$Config.Plugins.AHV
KVM_INSTALL =
[int]$Config.Plugins.KVM
PVE_INSTALL =
[int]$Config.Plugins.PVE
SCP_INSTALL =
[int]$Config.Plugins.SCP
AWS_INSTALL =
[int]$Config.Plugins.AWS
AZURE_INSTALL =
[int]$Config.Plugins.Azure
GCP_INSTALL =
[int]$Config.Plugins.GCP
KASTEN_INSTALL =
[int]$Config.Plugins.Kasten
}
Import-Configuration `
"C:\Scripte\VeeamConfig.json"
Initialize-Configuration