From 7f2eadf99ff4080d20576e4a2c5094488c2c59ea Mon Sep 17 00:00:00 2001 From: Madzone Date: Tue, 11 Aug 2026 09:52:19 +0200 Subject: [PATCH] Version 1.2 --- VEEAM-INSTALL/Config/VeeamConfig.json | 2 +- VEEAM-INSTALL/Configure-VeeamEnvironment.ps1 | 53 +++++++++++ VEEAM-INSTALL/Install-VeeamEnterprise.ps1 | 10 +- VEEAM-INSTALL/Modules/Platforms/HyperV.psm1 | 20 ++++ VEEAM-INSTALL/Modules/Platforms/Proxmox.psm1 | 23 +++++ VEEAM-INSTALL/Modules/Platforms/VMware.psm1 | 20 ++++ .../Modules/Veeam/VeeamInstallation.psm1 | 95 +++++++++++++++++++ 7 files changed, 219 insertions(+), 4 deletions(-) create mode 100644 VEEAM-INSTALL/Configure-VeeamEnvironment.ps1 create mode 100644 VEEAM-INSTALL/Modules/Platforms/HyperV.psm1 create mode 100644 VEEAM-INSTALL/Modules/Platforms/Proxmox.psm1 create mode 100644 VEEAM-INSTALL/Modules/Platforms/VMware.psm1 diff --git a/VEEAM-INSTALL/Config/VeeamConfig.json b/VEEAM-INSTALL/Config/VeeamConfig.json index cde291f..9c9b292 100644 --- a/VEEAM-INSTALL/Config/VeeamConfig.json +++ b/VEEAM-INSTALL/Config/VeeamConfig.json @@ -6,7 +6,7 @@ "Veeam": { "Version": "13.0.1.1071", - "SourcePath": "D:\\Install\\Veeam13" + "SourcePath": "Auto" }, "SQL": { diff --git a/VEEAM-INSTALL/Configure-VeeamEnvironment.ps1 b/VEEAM-INSTALL/Configure-VeeamEnvironment.ps1 new file mode 100644 index 0000000..dee28e5 --- /dev/null +++ b/VEEAM-INSTALL/Configure-VeeamEnvironment.ps1 @@ -0,0 +1,53 @@ +param( + [Parameter(Mandatory)] + [ValidateSet("VMware", "HyperV", "Proxmox")] + [string]$Platform, + + [Parameter(Mandatory)] + [string]$Server, + + [PSCredential]$Credential, + + [switch]$DryRun +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" +$Root = $PSScriptRoot + +$RequiredModules = @( + "Modules\Veeam\BackupJobs.psm1", + "Modules\Platforms\$Platform.psm1" +) + +foreach($Module in $RequiredModules) { + Import-Module (Join-Path $Root $Module) -Force -ErrorAction Stop +} + +$Configuration = Get-Content (Join-Path $Root "Config\VeeamConfig.json") -Raw | ConvertFrom-Json + +if($Platform -eq "Proxmox" -and $null -eq $Credential) { + $Credential = Get-Credential -Message "Proxmox API-Token-ID und Token-Secret eingeben" +} + +switch($Platform) { + "VMware" { $VirtualMachines = @(Get-VMwareInventory -Server $Server) } + "HyperV" { $VirtualMachines = @(Get-HyperVInventory -Server $Server) } + "Proxmox" { $VirtualMachines = @(Get-ProxmoxInventory -Server $Server -ApiCredential $Credential) } +} + +$Schedules = New-AlphabeticalBackupSchedules ` + -JobName $Configuration.BackupJob.Name ` + -VirtualMachines $VirtualMachines ` + -ScheduleGroups @($Configuration.BackupJob.ScheduleGroups) + +[PSCustomObject]@{ + Platform = $Platform + Server = $Server + DryRun = $DryRun.IsPresent + VirtualMachineCount = $VirtualMachines.Count + VirtualMachines = $VirtualMachines + Schedules = $Schedules + JobsCreated = $false + Message = "Inventar gelesen und Zeitplanentwurf erstellt. Es wurden keine Veeam-Jobs angelegt." +} diff --git a/VEEAM-INSTALL/Install-VeeamEnterprise.ps1 b/VEEAM-INSTALL/Install-VeeamEnterprise.ps1 index 20c9fd3..c780cc0 100644 --- a/VEEAM-INSTALL/Install-VeeamEnterprise.ps1 +++ b/VEEAM-INSTALL/Install-VeeamEnterprise.ps1 @@ -25,7 +25,8 @@ param( [Parameter(Mandatory=$false)] - [string]$VeeamSourcePath = "D:\Install\Veeam13", + [AllowEmptyString()] + [string]$VeeamSourcePath, [Parameter(Mandatory=$false)] @@ -526,8 +527,7 @@ function Start-VeeamEnterpriseInstall { param( - [Parameter(Mandatory)] - + [AllowEmptyString()] [string]$VeeamSourcePath, @@ -545,6 +545,10 @@ function Start-VeeamEnterpriseInstall { $Configuration = Get-InstallerConfiguration + $VeeamSourcePath = Resolve-VeeamSourcePath ` + -SourcePath $VeeamSourcePath ` + -ConfiguredPath ([string]$Configuration.Veeam.SourcePath) + $SystemCheck = Test-InstallerPrerequisites if($Script:IsDryRun) diff --git a/VEEAM-INSTALL/Modules/Platforms/HyperV.psm1 b/VEEAM-INSTALL/Modules/Platforms/HyperV.psm1 new file mode 100644 index 0000000..0e6a21b --- /dev/null +++ b/VEEAM-INSTALL/Modules/Platforms/HyperV.psm1 @@ -0,0 +1,20 @@ +Set-StrictMode -Version Latest + +function Get-HyperVInventory { + param([Parameter(Mandatory)][string]$Server) + + foreach($Command in @("Get-VBRServer", "Find-VBRHvEntity")) { + if($null -eq (Get-Command $Command -ErrorAction SilentlyContinue)) { + throw "Veeam-Befehl nicht verfügbar: $Command" + } + } + + $VBRServer = Get-VBRServer -Name $Server | Where-Object { $_.Type -in @("HvServer", "HvCluster", "Scvmm") } | Select-Object -First 1 + if($null -eq $VBRServer) { + throw "Hyper-V-Server ist in Veeam nicht registriert: $Server" + } + + @(Find-VBRHvEntity -Server $VBRServer -HostsAndVMs | Where-Object { $_.Type -match "Vm" } | Select-Object -ExpandProperty Name -Unique) +} + +Export-ModuleMember -Function Get-HyperVInventory diff --git a/VEEAM-INSTALL/Modules/Platforms/Proxmox.psm1 b/VEEAM-INSTALL/Modules/Platforms/Proxmox.psm1 new file mode 100644 index 0000000..d3c901a --- /dev/null +++ b/VEEAM-INSTALL/Modules/Platforms/Proxmox.psm1 @@ -0,0 +1,23 @@ +Set-StrictMode -Version Latest + +function Get-ProxmoxInventory { + param( + [Parameter(Mandatory)][string]$Server, + [Parameter(Mandatory)][PSCredential]$ApiCredential + ) + + $TokenSecret = $ApiCredential.GetNetworkCredential().Password + $Headers = @{ Authorization = "PVEAPIToken=$($ApiCredential.UserName)=$TokenSecret" } + $Uri = "https://$Server`:8006/api2/json/cluster/resources?type=vm" + + try { + $Response = Invoke-RestMethod -Method Get -Uri $Uri -Headers $Headers -ErrorAction Stop + @($Response.data | Where-Object { $_.type -eq "qemu" } | Select-Object -ExpandProperty name -Unique) + } + finally { + $TokenSecret = $null + $Headers = $null + } +} + +Export-ModuleMember -Function Get-ProxmoxInventory diff --git a/VEEAM-INSTALL/Modules/Platforms/VMware.psm1 b/VEEAM-INSTALL/Modules/Platforms/VMware.psm1 new file mode 100644 index 0000000..782e87a --- /dev/null +++ b/VEEAM-INSTALL/Modules/Platforms/VMware.psm1 @@ -0,0 +1,20 @@ +Set-StrictMode -Version Latest + +function Get-VMwareInventory { + param([Parameter(Mandatory)][string]$Server) + + foreach($Command in @("Get-VBRServer", "Find-VBRViEntity")) { + if($null -eq (Get-Command $Command -ErrorAction SilentlyContinue)) { + throw "Veeam-Befehl nicht verfügbar: $Command" + } + } + + $VBRServer = Get-VBRServer -Name $Server | Where-Object { $_.Type -in @("VC", "ESXi", "ESX") } | Select-Object -First 1 + if($null -eq $VBRServer) { + throw "VMware-Server ist in Veeam nicht registriert: $Server" + } + + @(Find-VBRViEntity -Server $VBRServer -VMsAndTemplates | Where-Object { $_.Type -match "Vm" } | Select-Object -ExpandProperty Name -Unique) +} + +Export-ModuleMember -Function Get-VMwareInventory diff --git a/VEEAM-INSTALL/Modules/Veeam/VeeamInstallation.psm1 b/VEEAM-INSTALL/Modules/Veeam/VeeamInstallation.psm1 index b790cd0..4240835 100644 --- a/VEEAM-INSTALL/Modules/Veeam/VeeamInstallation.psm1 +++ b/VEEAM-INSTALL/Modules/Veeam/VeeamInstallation.psm1 @@ -199,6 +199,100 @@ function Get-VeeamSetupFile { +############################################################ +# 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 +} + + + ############################################################ # Test-VeeamSource @@ -1370,6 +1464,7 @@ Export-ModuleMember ` Test-VeeamInstalled, Get-VeeamServices, Get-VeeamSetupFile, + Resolve-VeeamSourcePath, Test-VeeamSource, Get-VeeamRegistryInformation, Get-VeeamVersion,