1774 lines
32 KiB
PowerShell
1774 lines
32 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
|
|
|
|
}
|
|
|
|
|
|
|
|
############################################################
|
|
# Resolve-VeeamSourcePath
|
|
############################################################
|
|
|
|
function Resolve-VeeamSourcePath {
|
|
<#
|
|
.SYNOPSIS
|
|
Ermittelt die Installationsquelle aus Parameter, Konfiguration
|
|
oder eingelegten DVD-/ISO-Laufwerken.
|
|
#>
|
|
|
|
param(
|
|
[AllowEmptyString()][string]$SourcePath,
|
|
[AllowEmptyString()][string]$ConfiguredPath
|
|
)
|
|
|
|
if(![string]::IsNullOrWhiteSpace($SourcePath)) {
|
|
$SetupFile = Get-VeeamSetupFile -SourcePath $SourcePath
|
|
if($null -eq $SetupFile) {
|
|
throw "Keine Veeam.Silent.Install.exe in der angegebenen Quelle gefunden: $SourcePath"
|
|
}
|
|
|
|
return (Resolve-Path -Path $SourcePath).Path
|
|
}
|
|
|
|
$Candidates = @()
|
|
|
|
if(
|
|
![string]::IsNullOrWhiteSpace($ConfiguredPath) -and
|
|
$ConfiguredPath -ne "Auto" -and
|
|
(Test-Path -Path $ConfiguredPath)
|
|
) {
|
|
$Candidates += $ConfiguredPath
|
|
}
|
|
|
|
if($env:OS -eq "Windows_NT") {
|
|
try {
|
|
$OpticalDrives = Get-CimInstance Win32_LogicalDisk -Filter "DriveType = 5" -ErrorAction Stop
|
|
foreach($Drive in $OpticalDrives) {
|
|
if(![string]::IsNullOrWhiteSpace([string]$Drive.DeviceID)) {
|
|
$Candidates += ("{0}\" -f $Drive.DeviceID)
|
|
}
|
|
}
|
|
}
|
|
catch {
|
|
Write-Verbose "DVD-/ISO-Laufwerke konnten nicht über CIM ermittelt werden: $($_.Exception.Message)"
|
|
}
|
|
}
|
|
|
|
$ValidSources = @()
|
|
foreach($Candidate in @($Candidates | Select-Object -Unique)) {
|
|
if(!(Test-Path -Path $Candidate)) { continue }
|
|
|
|
try {
|
|
$SetupFile = Get-VeeamSetupFile -SourcePath $Candidate
|
|
if($null -ne $SetupFile) {
|
|
$ValidSources += [PSCustomObject]@{
|
|
SourcePath = (Resolve-Path -Path $Candidate).Path
|
|
SetupFile = $SetupFile
|
|
}
|
|
}
|
|
}
|
|
catch {
|
|
Write-Verbose "Quelle wurde übersprungen: $Candidate"
|
|
}
|
|
}
|
|
|
|
if($ValidSources.Count -eq 0) {
|
|
throw "Keine Veeam-Installationsquelle gefunden. DVD/ISO einlegen oder -VeeamSourcePath angeben."
|
|
}
|
|
|
|
if($ValidSources.Count -eq 1) {
|
|
return $ValidSources[0].SourcePath
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "Mehrere Veeam-Installationsquellen gefunden:" -ForegroundColor Cyan
|
|
for($Index = 0; $Index -lt $ValidSources.Count; $Index++) {
|
|
Write-Host ("{0} - {1}" -f ($Index + 1), $ValidSources[$Index].SourcePath)
|
|
}
|
|
|
|
do {
|
|
$Selection = Read-Host "Installationsquelle auswählen (1-$($ValidSources.Count))"
|
|
$SelectedIndex = 0
|
|
$SelectionValid = [int]::TryParse($Selection, [ref]$SelectedIndex) -and
|
|
$SelectedIndex -ge 1 -and
|
|
$SelectedIndex -le $ValidSources.Count
|
|
} until($SelectionValid)
|
|
|
|
return $ValidSources[$SelectedIndex - 1].SourcePath
|
|
}
|
|
|
|
|
|
|
|
############################################################
|
|
# Resolve-VeeamAnswerFile
|
|
############################################################
|
|
|
|
function Resolve-VeeamAnswerFile {
|
|
<#
|
|
.SYNOPSIS
|
|
Ermittelt die Antwortdatei lokal oder relativ zur Installationsquelle.
|
|
#>
|
|
|
|
param(
|
|
[AllowEmptyString()][string]$AnswerFile,
|
|
[Parameter(Mandatory)][string]$SourcePath,
|
|
[Parameter(Mandatory)][string]$LocalConfigPath,
|
|
[ValidateSet("MSSQL", "PostgreSQL")][string]$DatabaseEngine = "MSSQL",
|
|
[string]$SQLServer,
|
|
[string]$SQLInstance,
|
|
[string]$DatabaseName = "VeeamBackup"
|
|
)
|
|
|
|
if(![string]::IsNullOrWhiteSpace($AnswerFile)) {
|
|
if(!(Test-Path -LiteralPath $AnswerFile -PathType Leaf)) {
|
|
throw "Explizit angegebene Veeam-Antwortdatei nicht gefunden: $AnswerFile"
|
|
}
|
|
|
|
return (Resolve-Path -LiteralPath $AnswerFile).Path
|
|
}
|
|
|
|
$LocalAnswerFile = Join-Path $LocalConfigPath "VeeamAnswerFile.xml"
|
|
if(Test-Path -LiteralPath $LocalAnswerFile -PathType Leaf) {
|
|
[xml]$LocalXml = Get-Content -LiteralPath $LocalAnswerFile -Raw
|
|
$RequiredValues = @(
|
|
"ACCEPT_EULA",
|
|
"ACCEPT_LICENSING_POLICY",
|
|
"ACCEPT_THIRDPARTY_LICENSES",
|
|
"ACCEPT_REQUIRED_SOFTWARE"
|
|
)
|
|
$Configured = $true
|
|
|
|
foreach($RequiredValue in $RequiredValues) {
|
|
$Node = $LocalXml.SelectSingleNode("//property[@name='$RequiredValue']")
|
|
if($null -eq $Node -or $Node.value -ne "1") {
|
|
$Configured = $false
|
|
break
|
|
}
|
|
}
|
|
|
|
# Ohne benutzerdefinierte Dienstkonto-Felder verwendet Veeam den
|
|
# empfohlenen LocalSystem-Standard. Vorlagenwerte würden sonst als
|
|
# echte Anmeldedaten validiert und die Installation blockieren.
|
|
foreach($ServiceProperty in @("VBR_SERVICE_USER", "VBR_SERVICE_PASSWORD")) {
|
|
if($null -ne $LocalXml.SelectSingleNode("//property[@name='$ServiceProperty']")) {
|
|
$Configured = $false
|
|
}
|
|
}
|
|
|
|
$InstallNode = $LocalXml.SelectSingleNode("//property[@name='VBR_SQLSERVER_INSTALL']")
|
|
$ExpectedInstallValue = if($DatabaseEngine -eq "MSSQL") { "0" } else { "1" }
|
|
if($null -eq $InstallNode -or $InstallNode.value -ne $ExpectedInstallValue) {
|
|
$Configured = $false
|
|
}
|
|
|
|
if($DatabaseEngine -eq "MSSQL") {
|
|
$ExpectedSqlTarget = "{0}\{1}" -f $SQLServer, $SQLInstance
|
|
$EngineNode = $LocalXml.SelectSingleNode("//property[@name='VBR_SQLSERVER_ENGINE']")
|
|
$ServerNode = $LocalXml.SelectSingleNode("//property[@name='VBR_SQLSERVER_SERVER']")
|
|
$DatabaseNode = $LocalXml.SelectSingleNode("//property[@name='VBR_SQLSERVER_DATABASE']")
|
|
|
|
if(
|
|
$null -eq $EngineNode -or $EngineNode.value -ne "0" -or
|
|
$null -eq $ServerNode -or $ServerNode.value -ne $ExpectedSqlTarget -or
|
|
$null -eq $DatabaseNode -or $DatabaseNode.value -ne $DatabaseName
|
|
) {
|
|
$Configured = $false
|
|
}
|
|
}
|
|
|
|
if($Configured) {
|
|
return (Resolve-Path -LiteralPath $LocalAnswerFile).Path
|
|
}
|
|
|
|
return New-VeeamAnswerFileFromTemplate `
|
|
-TemplatePath $LocalAnswerFile `
|
|
-DestinationPath $LocalAnswerFile `
|
|
-DatabaseEngine $DatabaseEngine `
|
|
-SQLServer $SQLServer `
|
|
-SQLInstance $SQLInstance `
|
|
-DatabaseName $DatabaseName
|
|
}
|
|
|
|
$SourceRoot = $SourcePath
|
|
if(Test-Path -LiteralPath $SourcePath -PathType Leaf) {
|
|
$SourceRoot = Split-Path -Parent $SourcePath
|
|
}
|
|
|
|
$Candidates = @(
|
|
(Join-Path $SourceRoot "VeeamAnswerFile.xml"),
|
|
(Join-Path $SourceRoot "Setup\Silent\VeeamAnswerFile.xml"),
|
|
(Join-Path $SourceRoot "Setup\Silent\AnswerFiles\VBR\VbrAnswerFile_install.xml")
|
|
)
|
|
|
|
foreach($Candidate in $Candidates) {
|
|
if(Test-Path -LiteralPath $Candidate -PathType Leaf) {
|
|
if([IO.Path]::GetFileName($Candidate) -eq "VbrAnswerFile_install.xml") {
|
|
return New-VeeamAnswerFileFromTemplate `
|
|
-TemplatePath $Candidate `
|
|
-DestinationPath $LocalAnswerFile `
|
|
-DatabaseEngine $DatabaseEngine `
|
|
-SQLServer $SQLServer `
|
|
-SQLInstance $SQLInstance `
|
|
-DatabaseName $DatabaseName
|
|
}
|
|
|
|
return (Resolve-Path -LiteralPath $Candidate).Path
|
|
}
|
|
}
|
|
|
|
$DiscoveredTemplate = Get-ChildItem `
|
|
-LiteralPath $SourceRoot `
|
|
-Recurse `
|
|
-Filter "VbrAnswerFile_install.xml" `
|
|
-File `
|
|
-ErrorAction SilentlyContinue |
|
|
Select-Object -First 1
|
|
|
|
if($null -ne $DiscoveredTemplate) {
|
|
return New-VeeamAnswerFileFromTemplate `
|
|
-TemplatePath $DiscoveredTemplate.FullName `
|
|
-DestinationPath $LocalAnswerFile `
|
|
-DatabaseEngine $DatabaseEngine `
|
|
-SQLServer $SQLServer `
|
|
-SQLInstance $SQLInstance `
|
|
-DatabaseName $DatabaseName
|
|
}
|
|
|
|
throw "Keine Veeam-Antwortdatei gefunden. Erwartet: Config\VeeamAnswerFile.xml oder DVD-Vorlage VbrAnswerFile_install.xml."
|
|
}
|
|
|
|
|
|
|
|
############################################################
|
|
# New-VeeamAnswerFileFromTemplate
|
|
############################################################
|
|
|
|
function New-VeeamAnswerFileFromTemplate {
|
|
param(
|
|
[Parameter(Mandatory)][string]$TemplatePath,
|
|
[Parameter(Mandatory)][string]$DestinationPath,
|
|
[ValidateSet("MSSQL", "PostgreSQL")][string]$DatabaseEngine = "MSSQL",
|
|
[string]$SQLServer,
|
|
[string]$SQLInstance,
|
|
[string]$DatabaseName = "VeeamBackup"
|
|
)
|
|
|
|
if(!(Test-Path -LiteralPath $TemplatePath -PathType Leaf)) {
|
|
throw "Veeam-Antwortvorlage nicht gefunden: $TemplatePath"
|
|
}
|
|
|
|
Write-Host ""
|
|
Write-Host "Veeam-Lizenzzustimmungen werden in der Antwortdatei automatisch gesetzt." -ForegroundColor Cyan
|
|
|
|
$DestinationDirectory = Split-Path -Parent $DestinationPath
|
|
if(!(Test-Path -LiteralPath $DestinationDirectory -PathType Container)) {
|
|
New-Item -Path $DestinationDirectory -ItemType Directory -Force | Out-Null
|
|
}
|
|
|
|
$TemplateFullPath = [IO.Path]::GetFullPath($TemplatePath)
|
|
$DestinationFullPath = [IO.Path]::GetFullPath($DestinationPath)
|
|
|
|
if($TemplateFullPath -ne $DestinationFullPath) {
|
|
Copy-Item -LiteralPath $TemplatePath -Destination $DestinationPath -Force
|
|
}
|
|
|
|
# Beim Kopieren von DVD/ISO kann das ReadOnly-Attribut erhalten bleiben.
|
|
# Vor dem Speichern muss die lokale Antwortdatei beschreibbar sein.
|
|
$DestinationItem = Get-Item -LiteralPath $DestinationPath -ErrorAction Stop
|
|
if($DestinationItem.IsReadOnly) {
|
|
$DestinationItem.IsReadOnly = $false
|
|
}
|
|
|
|
[xml]$Xml = Get-Content -LiteralPath $DestinationPath -Raw
|
|
$Root = $Xml.unattendedInstallationConfiguration
|
|
|
|
if($null -eq $Root -or $Root.bundle -ne "Vbr" -or $Root.mode -ne "install") {
|
|
throw "Ungültige Veeam-VBR-Installationsvorlage: $TemplatePath"
|
|
}
|
|
|
|
$PropertiesNode = $Root.properties
|
|
if($null -eq $PropertiesNode) {
|
|
throw "Eigenschaftsblock fehlt in der Veeam-Antwortvorlage."
|
|
}
|
|
|
|
function Set-AnswerProperty {
|
|
param([string]$Name, [string]$Value)
|
|
|
|
$Node = $Xml.SelectSingleNode("//property[@name='$Name']")
|
|
if($null -eq $Node) {
|
|
$Node = $Xml.CreateElement("property")
|
|
$Node.SetAttribute("name", $Name)
|
|
$PropertiesNode.AppendChild($Node) | Out-Null
|
|
}
|
|
|
|
$Node.SetAttribute("value", $Value)
|
|
}
|
|
|
|
foreach($Agreement in @(
|
|
"ACCEPT_EULA",
|
|
"ACCEPT_LICENSING_POLICY",
|
|
"ACCEPT_THIRDPARTY_LICENSES",
|
|
"ACCEPT_REQUIRED_SOFTWARE"
|
|
)) {
|
|
Set-AnswerProperty -Name $Agreement -Value "1"
|
|
}
|
|
|
|
if($DatabaseEngine -eq "MSSQL") {
|
|
if([string]::IsNullOrWhiteSpace($SQLServer) -or [string]::IsNullOrWhiteSpace($SQLInstance)) {
|
|
throw "Für Microsoft SQL müssen Server und Instanz angegeben sein."
|
|
}
|
|
|
|
Set-AnswerProperty -Name "VBR_SQLSERVER_INSTALL" -Value "0"
|
|
Set-AnswerProperty -Name "VBR_SQLSERVER_ENGINE" -Value "0"
|
|
Set-AnswerProperty -Name "VBR_SQLSERVER_SERVER" -Value ("{0}\{1}" -f $SQLServer, $SQLInstance)
|
|
Set-AnswerProperty -Name "VBR_SQLSERVER_DATABASE" -Value $DatabaseName
|
|
Set-AnswerProperty -Name "VBR_SQLSERVER_AUTHENTICATION" -Value "0"
|
|
$UnusedProperties = @(
|
|
"VBR_SERVICE_USER",
|
|
"VBR_SERVICE_PASSWORD",
|
|
"VBR_SQLSERVER_USERNAME",
|
|
"VBR_SQLSERVER_PASSWORD"
|
|
)
|
|
}
|
|
else {
|
|
Set-AnswerProperty -Name "VBR_SQLSERVER_INSTALL" -Value "1"
|
|
Set-AnswerProperty -Name "VBR_SQLSERVER_DATABASE" -Value $DatabaseName
|
|
$UnusedProperties = @(
|
|
"VBR_SERVICE_USER",
|
|
"VBR_SERVICE_PASSWORD",
|
|
"VBR_SQLSERVER_ENGINE",
|
|
"VBR_SQLSERVER_SERVER",
|
|
"VBR_SQLSERVER_AUTHENTICATION",
|
|
"VBR_SQLSERVER_USERNAME",
|
|
"VBR_SQLSERVER_PASSWORD"
|
|
)
|
|
}
|
|
|
|
foreach($UnusedProperty in $UnusedProperties) {
|
|
$Node = $Xml.SelectSingleNode("//property[@name='$UnusedProperty']")
|
|
if($null -ne $Node) {
|
|
$Node.ParentNode.RemoveChild($Node) | Out-Null
|
|
}
|
|
}
|
|
|
|
$Xml.Save($DestinationPath)
|
|
|
|
Write-Host "Konfigurierte Antwortdatei erstellt: $DestinationPath" -ForegroundColor Green
|
|
return (Resolve-Path -LiteralPath $DestinationPath).Path
|
|
}
|
|
|
|
|
|
|
|
############################################################
|
|
# 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."
|
|
|
|
}
|
|
|
|
|
|
|
|
if([string]::IsNullOrWhiteSpace($LogFolder))
|
|
{
|
|
$LogFolder = "C:\ProgramData\VeeamInstaller\SetupLogs"
|
|
}
|
|
|
|
if(!(Test-Path -LiteralPath $LogFolder -PathType Container))
|
|
{
|
|
New-Item -Path $LogFolder -ItemType Directory -Force | Out-Null
|
|
}
|
|
|
|
|
|
$Arguments =
|
|
|
|
New-VeeamInstallParameter `
|
|
-AnswerFile $AnswerFile `
|
|
-LogFolder $LogFolder `
|
|
-SkipNetworkLogonErrors:$SkipNetworkLogonErrors
|
|
|
|
|
|
|
|
$Result =
|
|
|
|
Start-VeeamSetup `
|
|
-SetupFile $Setup `
|
|
-Arguments $Arguments
|
|
|
|
|
|
|
|
return [PSCustomObject]@{
|
|
|
|
|
|
Preparation =
|
|
|
|
$Preparation
|
|
|
|
|
|
|
|
Setup =
|
|
|
|
$Setup
|
|
|
|
|
|
|
|
Result =
|
|
|
|
$Result
|
|
|
|
|
|
|
|
LogFolder =
|
|
|
|
$LogFolder
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
############################################################
|
|
# 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,
|
|
Resolve-VeeamSourcePath,
|
|
Resolve-VeeamAnswerFile,
|
|
New-VeeamAnswerFileFromTemplate,
|
|
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
|
|
############################################################
|