Version 1.0 of Configure
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
param(
|
||||
[ValidateSet("VMware", "HyperV", "Proxmox")]
|
||||
[string]$Platform,
|
||||
|
||||
[string]$Server,
|
||||
|
||||
[PSCredential]$Credential,
|
||||
[switch]$TrustSelfSignedCertificate,
|
||||
[switch]$DryRun,
|
||||
[switch]$Apply,
|
||||
[switch]$NonInteractive
|
||||
)
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
$ErrorActionPreference = "Stop"
|
||||
$Root = $PSScriptRoot
|
||||
|
||||
if($DryRun.IsPresent -and $Apply.IsPresent) {
|
||||
throw "-DryRun und -Apply dürfen nicht gleichzeitig verwendet werden."
|
||||
}
|
||||
|
||||
if($Apply.IsPresent) {
|
||||
throw "Produktivmodus ist noch gesperrt: Die echte Veeam-Jobanlage ist noch nicht implementiert."
|
||||
}
|
||||
|
||||
if([string]::IsNullOrWhiteSpace($Platform)) {
|
||||
if($NonInteractive) {
|
||||
throw "Im nicht interaktiven Modus ist -Platform erforderlich."
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Veeam Umgebungsassistent" -ForegroundColor Cyan
|
||||
Write-Host "1 - VMware vCenter"
|
||||
Write-Host "2 - Microsoft Hyper-V"
|
||||
Write-Host "3 - Proxmox VE"
|
||||
|
||||
do {
|
||||
$Selection = Read-Host "Plattform auswählen (1-3)"
|
||||
} until($Selection -in @("1", "2", "3"))
|
||||
|
||||
$Platform = switch($Selection) {
|
||||
"1" { "VMware" }
|
||||
"2" { "HyperV" }
|
||||
"3" { "Proxmox" }
|
||||
}
|
||||
}
|
||||
|
||||
if([string]::IsNullOrWhiteSpace($Server)) {
|
||||
if($NonInteractive) {
|
||||
throw "Im nicht interaktiven Modus ist -Server erforderlich."
|
||||
}
|
||||
|
||||
do {
|
||||
$Server = Read-Host "DNS-Name oder IP-Adresse des $Platform-Servers"
|
||||
} until(![string]::IsNullOrWhiteSpace($Server))
|
||||
}
|
||||
|
||||
if(!$DryRun.IsPresent -and !$Apply.IsPresent) {
|
||||
$DryRun = $true
|
||||
}
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Plattform : $Platform" -ForegroundColor Yellow
|
||||
Write-Host "Server : $Server" -ForegroundColor Yellow
|
||||
Write-Host "Modus : Vorschau / Dry-Run" -ForegroundColor Yellow
|
||||
|
||||
Import-Module (Join-Path $Root "Modules\Scheduling.psm1") -Force -ErrorAction Stop
|
||||
Import-Module (Join-Path $Root "Modules\Platforms\$Platform.psm1") -Force -ErrorAction Stop
|
||||
|
||||
$ConfigPath = Join-Path $Root "Config\VeeamConfigure.json"
|
||||
$Configuration = Get-Content -LiteralPath $ConfigPath -Raw | ConvertFrom-Json
|
||||
|
||||
if($Platform -eq "Proxmox" -and $null -eq $Credential) {
|
||||
$Credential = Get-Credential -Message "Proxmox API-Token-ID und Token-Secret eingeben"
|
||||
}
|
||||
|
||||
if($Platform -eq "Proxmox" -and !$TrustSelfSignedCertificate.IsPresent -and !$NonInteractive) {
|
||||
$CertificateAnswer = Read-Host "Selbstsigniertes Proxmox-Zertifikat temporär akzeptieren? [j/N]"
|
||||
if($CertificateAnswer -match '^(j|ja|y|yes)$') {
|
||||
$TrustSelfSignedCertificate = $true
|
||||
}
|
||||
}
|
||||
|
||||
switch($Platform) {
|
||||
"VMware" { $VirtualMachines = @(Get-VMwareInventory -Server $Server) }
|
||||
"HyperV" { $VirtualMachines = @(Get-HyperVInventory -Server $Server) }
|
||||
"Proxmox" {
|
||||
$VirtualMachines = @(
|
||||
Get-ProxmoxInventory `
|
||||
-Server $Server `
|
||||
-ApiCredential $Credential `
|
||||
-TrustSelfSignedCertificate:$TrustSelfSignedCertificate
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
$Schedules = New-AlphabeticalSchedulePlan `
|
||||
-JobName $Configuration.BackupJob.Name `
|
||||
-VirtualMachines $VirtualMachines `
|
||||
-ScheduleGroups @($Configuration.BackupJob.ScheduleGroups)
|
||||
|
||||
Write-Host ""
|
||||
Write-Host "Gefundene VMs: $($VirtualMachines.Count)" -ForegroundColor Cyan
|
||||
|
||||
foreach($Schedule in $Schedules) {
|
||||
Write-Host ("{0,-24} {1} {2}" -f $Schedule.JobName, $Schedule.Time, ($Schedule.VirtualMachines -join ", "))
|
||||
}
|
||||
|
||||
[PSCustomObject]@{
|
||||
Platform = $Platform
|
||||
Server = $Server
|
||||
DryRun = $DryRun.IsPresent
|
||||
VirtualMachineCount = $VirtualMachines.Count
|
||||
VirtualMachines = $VirtualMachines
|
||||
Schedules = $Schedules
|
||||
JobsCreated = $false
|
||||
Message = "Inventar gelesen und Zeitplanentwurf erstellt. Keine Veeam-Jobs angelegt."
|
||||
}
|
||||
Reference in New Issue
Block a user