From 780f5c4cfa99a4eb3bc18727ddec320d1ea63bc3 Mon Sep 17 00:00:00 2001 From: Madzone Date: Thu, 6 Aug 2026 22:40:17 +0200 Subject: [PATCH] =?UTF-8?q?git=20add=20.=20git=20commit=20-m=20"Neue=20Skr?= =?UTF-8?q?ipte=20hinzugef=C3=BCgt"=20git=20push?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VEEAM-INSTTALL/Config/VeeamConfig.json | 35 + VEEAM-INSTTALL/Install-VeeamEnterprise.ps1 | 909 +++++++++ VEEAM-INSTTALL/Modules/CORE/Bootstrap.psm1 | 595 ++++++ .../Modules/CORE/Configuration.psm1 | 1283 +++++++++++++ VEEAM-INSTTALL/Modules/CORE/DryRun.psm1 | 645 +++++++ VEEAM-INSTTALL/Modules/CORE/Logging.psm1 | 1701 +++++++++++++++++ VEEAM-INSTTALL/Modules/CORE/SQL.psm1 | 1383 ++++++++++++++ VEEAM-INSTTALL/Modules/CORE/Security.psm1 | 1281 +++++++++++++ VEEAM-INSTTALL/Modules/CORE/Utilities.psm1 | 1510 +++++++++++++++ VEEAM-INSTTALL/Modules/Veeam/BackupJobs.psm1 | 1223 ++++++++++++ VEEAM-INSTTALL/Modules/Veeam/Repository.psm1 | 1359 +++++++++++++ .../Modules/Veeam/VeeamInstallation.psm1 | 1428 ++++++++++++++ VEEAM-INSTTALL/Scripts/Test-VeeamModules.ps1 | 561 ++++++ 13 files changed, 13913 insertions(+) create mode 100644 VEEAM-INSTTALL/Config/VeeamConfig.json create mode 100644 VEEAM-INSTTALL/Install-VeeamEnterprise.ps1 create mode 100644 VEEAM-INSTTALL/Modules/CORE/Bootstrap.psm1 create mode 100644 VEEAM-INSTTALL/Modules/CORE/Configuration.psm1 create mode 100644 VEEAM-INSTTALL/Modules/CORE/DryRun.psm1 create mode 100644 VEEAM-INSTTALL/Modules/CORE/Logging.psm1 create mode 100644 VEEAM-INSTTALL/Modules/CORE/SQL.psm1 create mode 100644 VEEAM-INSTTALL/Modules/CORE/Security.psm1 create mode 100644 VEEAM-INSTTALL/Modules/CORE/Utilities.psm1 create mode 100644 VEEAM-INSTTALL/Modules/Veeam/BackupJobs.psm1 create mode 100644 VEEAM-INSTTALL/Modules/Veeam/Repository.psm1 create mode 100644 VEEAM-INSTTALL/Modules/Veeam/VeeamInstallation.psm1 create mode 100644 VEEAM-INSTTALL/Scripts/Test-VeeamModules.ps1 diff --git a/VEEAM-INSTTALL/Config/VeeamConfig.json b/VEEAM-INSTTALL/Config/VeeamConfig.json new file mode 100644 index 0000000..fdf0840 --- /dev/null +++ b/VEEAM-INSTTALL/Config/VeeamConfig.json @@ -0,0 +1,35 @@ +{ + "Environment": { + "Name": "Production", + "Owner": "IT" + }, + + "Veeam": { + "Version": "13.0.1.1071", + "SourcePath": "D:\\Install\\Veeam13" + }, + + "SQL": { + "Server": "SERVER01", + "Instance": "VEEAMSQLSERVER", + "Database": "VeeamBackup" + }, + + "Repository": { + "Name": "PrimaryRepository", + "Path": "D:\\VeeamRepository", + "RetentionDays": 30 + }, + + "BackupJob": { + "Name": "ServerBackup", + "Schedule": "22:00", + "Enabled": true + }, + + "Options": { + "ApplicationAware": true, + "Encryption": true, + "Compression": "Optimal" + } +} \ No newline at end of file diff --git a/VEEAM-INSTTALL/Install-VeeamEnterprise.ps1 b/VEEAM-INSTTALL/Install-VeeamEnterprise.ps1 new file mode 100644 index 0000000..7107652 --- /dev/null +++ b/VEEAM-INSTTALL/Install-VeeamEnterprise.ps1 @@ -0,0 +1,909 @@ +<# +.SYNOPSIS + Veeam Enterprise Installer + +.DESCRIPTION + Automatisierte Installation und Konfiguration von: + - Veeam Backup & Replication + - SQL Konfiguration + - Repository + - Backup Jobs + - Reporting + - Logging + - Dry-Run Unterstützung + +.VERSION + 1.0.0 +#> + + +Set-StrictMode -Version Latest + + +############################################################ +# Script Parameter +############################################################ + +param( + + [Parameter(Mandatory=$false)] + + [string]$VeeamSourcePath = + + "D:\Install\Veeam13", + + + + [Parameter(Mandatory=$false)] + + [switch]$DryRun + +) + + + +############################################################ +# Globale Variablen +############################################################ + +$Script:InstallerRoot = + + Split-Path ` + $PSScriptRoot ` + -Parent + + + +$Script:ModulePath = + + Join-Path ` + $Script:InstallerRoot ` + "Modules" + + + +$Script:ConfigPath = + + Join-Path ` + $Script:InstallerRoot ` + "Config\VeeamConfig.json" + + + +############################################################ +# Import Installer Module +############################################################ + +function Import-InstallerModules { + + + $Modules = @( + + "Core\Logging.psm1", + + "Core\Configuration.psm1", + + "Core\Utilities.psm1", + + "Core\Security.psm1", + + "Core\SQL.psm1", + + "Core\DryRun.psm1", + + "Veeam\VeeamInstallation.psm1", + + "Veeam\Repository.psm1", + + "Veeam\BackupJobs.psm1" + + ) + + + + foreach($Module in $Modules) + { + + + $Path = + + Join-Path ` + + $Script:ModulePath ` + + $Module + + + + if(Test-Path $Path) + { + + Import-Module ` + + $Path ` + + -Force + + } + else + { + + throw ` + + "Modul nicht gefunden: $Path" + + } + + } + +} +#Begin PART 2 +############################################################ +# Installer Initialisierung +############################################################ + +function Initialize-Installer { + + + Write-Host "" + + Write-Host ` + "Initialisiere Veeam Enterprise Installer..." ` + -ForegroundColor Cyan + + + + Test-AdministratorRights + + + + Import-InstallerModules + + + + Write-Host ` + "Module erfolgreich geladen." ` + -ForegroundColor Green + +} + + + +############################################################ +# Administrator Prüfung +############################################################ + +function Test-AdministratorRights { + + + $CurrentUser = + + [Security.Principal.WindowsIdentity]::GetCurrent() + + + + $Principal = + + New-Object ` + Security.Principal.WindowsPrincipal( + $CurrentUser + ) + + + + if( + !$Principal.IsInRole( + [Security.Principal.WindowsBuiltInRole]::Administrator + ) + ) + { + + throw ` + "Script muss als Administrator ausgeführt werden." + + } + +} + + + +############################################################ +# Konfiguration laden +############################################################ + +function Get-InstallerConfiguration { + + + $Config = + + Get-VeeamConfig + + + + $Validation = + + Test-VeeamConfig ` + + -Configuration $Config + + + + if(!$Validation.Valid) + { + + throw ` + "Konfigurationsprüfung fehlgeschlagen." + + } + + + + return $Config + +} + + + +############################################################ +# Voraussetzungen prüfen +############################################################ + +function Test-InstallerPrerequisites { + + + Write-Host "" + + Write-Host ` + "Prüfe Systemvoraussetzungen..." ` + -ForegroundColor Yellow + + + + $Checks = @() + + + + $Checks += + + [PSCustomObject]@{ + + Name = + + "Administrator" + + + + Result = + + $true + + } + + + + $Checks += + + [PSCustomObject]@{ + + Name = + + "PowerShell" + + + + Result = + + ( + $PSVersionTable.PSVersion.Major -ge 5 + ) + + } + + + + return $Checks + +} +#Begin PART 3 +############################################################ +# SQL Prüfung +############################################################ + +function Test-InstallerSQL { + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Configuration + + ) + + + + Write-Host "" + + Write-Host ` + "Prüfe SQL Konfiguration..." ` + -ForegroundColor Yellow + + + + $Result = + + Test-SQLConfiguration ` + + -Server $Configuration.SQL.Server ` + + -Instance $Configuration.SQL.Instance ` + + -Database $Configuration.SQL.Database + + + + return $Result + +} + + + +############################################################ +# Veeam Installation +############################################################ + +function Install-VeeamProduct { + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Configuration, + + + [Parameter(Mandatory)] + + [string]$SourcePath + + ) + + + + Write-Host "" + + Write-Host ` + "Installiere Veeam..." ` + -ForegroundColor Yellow + + + + if($DryRun) + { + + return ( + + Test-DryRunInstallation -SourcePath $SourcePath -SQLServer $Configuration.SQL.Server -Database $Configuration.SQL.Database + + ) + + } + + + + return ( + + Invoke-VeeamInstallation -SourcePath $SourcePath -SQLServer $Configuration.SQL.Server -SQLInstance $Configuration.SQL.Instance -Database $Configuration.SQL.Database + + ) + +} + + + +############################################################ +# Repository Initialisierung +############################################################ + +function Initialize-BackupRepository { + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Configuration + + ) + + + + Write-Host "" + + Write-Host ` + "Erstelle Repository..." ` + -ForegroundColor Yellow + + + + if($DryRun) + { + + return ( + + Test-DryRunRepository -Name $Configuration.Repository.Name -Path $Configuration.Repository.Path + + ) + + } + + + + return ( + + Deploy-RepositoryConfiguration -Name $Configuration.Repository.Name -Path $Configuration.Repository.Path -RetentionDays $Configuration.Repository.RetentionDays + + ) + +} +#Begin PART 4 +############################################################ +# Backup Job Initialisierung +############################################################ + +function Initialize-BackupJobs +{ + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Configuration + + ) + + Write-Host "" + + Write-Host ` + "Erstelle Backup Jobs..." ` + -ForegroundColor Yellow + + + + if($DryRun) + { + + return ( + + Test-DryRunBackupJob -Name $Configuration.BackupJob.Name -Repository $Configuration.Repository.Name -RetentionDays $Configuration.Repository.RetentionDays + + ) + + } + + + + $Job = + + New-BackupJobDefinition ` + + -Name $Configuration.BackupJob.Name ` + + -Repository $Configuration.Repository.Name ` + + -RetentionDays $Configuration.Repository.RetentionDays + + + + $Schedule = New-BackupSchedule -Time $Configuration.BackupJob.Schedule + + $ApplicationAware = New-ApplicationAwareConfiguration -Enabled $Configuration.Options.ApplicationAware + + + + return [PSCustomObject]@{ + + + Job = $Job + + Schedule = $Schedule + + ApplicationAware = $ApplicationAware + + } + +} + + + +############################################################ +# Haupt Installationsablauf +############################################################ + +function Start-VeeamEnterpriseInstall { + + + param( + + [Parameter(Mandatory)] + + [string]$VeeamSourcePath + + ) + + + + try + { + + + $Configuration = Get-InstallerConfiguration + + if($DryRun) + { + + Write-Host "" + + Write-Host "DRY-RUN aktiviert" -ForegroundColor Yellow + + $Simulation = Invoke-DryRunPipeline -Configuration $Configuration + + return ( + + Get-DryRunReport -Results $Simulation + + ) + + } + + + + $SystemCheck = Test-InstallerPrerequisites + + $SQLCheck = Test-InstallerSQL -Configuration $Configuration + + $Installation = Install-VeeamProduct -Configuration $Configuration -SourcePath $VeeamSourcePath + + $Repository = Initialize-BackupRepository -Configuration $Configuration + + $Jobs = Initialize-BackupJobs -Configuration $Configuration + + + + return [PSCustomObject]@{ + + Configuration = $Configuration + + System = $SystemCheck + + SQL = $SQLCheck + + Installation = $Installation + + Repository = $Repository + + Jobs =$Jobs + + Completed = Get-Date + + } + + } + + catch + { + Write-ExceptionLog -Exception $_.Exception -Context "Installation" + throw + } + +} +#Begin PART 5 +############################################################ +# Enterprise Report +############################################################ + +function Get-EnterpriseInstallationReport { + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Result + + ) + + + + [PSCustomObject]@{ + + + Computer = + + $env:COMPUTERNAME + + + + Mode = + + if($DryRun) + { + + "DryRun" + + } + else + { + + "Production" + + } + + + + VeeamVersion = + + $Result.Configuration.Veeam.Version + + + + SQLServer = + + $Result.Configuration.SQL.Server + + + + SQLInstance = + + $Result.Configuration.SQL.Instance + + + + Database = + + $Result.Configuration.SQL.Database + + + + Repository = + + $Result.Configuration.Repository.Path + + + + BackupJob = + + $Result.Configuration.BackupJob.Name + + + + Completed = + + Get-Date + + } + +} + + + +############################################################ +# Report speichern +############################################################ + +function Save-EnterpriseReport { + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Report + + ) + + + + $Path = + + Join-Path ` + + $Script:InstallerRoot ` + + "Reports" + + + + if(!(Test-Path $Path)) + { + + New-Item ` + + -Path $Path ` + + -ItemType Directory ` + + -Force | + + Out-Null + + } + + + + $File = + + Join-Path ` + + $Path ` + + ( + "EnterpriseReport_" + + + ( + Get-Date ` + -Format "yyyyMMdd_HHmmss" + ) + + + ".json" + + ) + + + + $Report | + + ConvertTo-Json ` + + -Depth 10 | + + Out-File ` + + -FilePath $File ` + + -Encoding UTF8 + + + + return $File + +} + + + +############################################################ +# Hauptausführung +############################################################ + +try +{ + + Initialize-Installer + + + + Initialize-EnterpriseLog ` + + -Name "VeeamEnterprise" + + + + Write-EnterpriseLog ` + + -Level INFO ` + + -Message "Installer gestartet" + + + + if($DryRun) + { + + Enable-DryRunMode + + Write-EnterpriseLog ` + + -Level INFO ` + + -Message "DryRun aktiviert" + + } + + + + $Result = + + Start-VeeamEnterpriseInstall ` + + -VeeamSourcePath $VeeamSourcePath + + + + $Report = + + Get-EnterpriseInstallationReport ` + + -Result $Result + + + + $ReportFile = + + Save-EnterpriseReport ` + + -Report $Report + + + + Write-EnterpriseLog ` + + -Level INFO ` + + -Message ( + + "Installation abgeschlossen: " + + $ReportFile + + ) + + + + Write-Host "" + + Write-Host ` + "Installation abgeschlossen" ` + -ForegroundColor Green + + + + Write-Host ` + $ReportFile ` + -ForegroundColor Cyan + + +} +catch +{ + + Write-ExceptionLog ` + + -Exception $_.Exception ` + + -Context "Main Installer" + + + + Write-Host "" + + Write-Host ` + "Installation fehlgeschlagen" ` + -ForegroundColor Red + + + + exit 1 + +} +#Begin PART 6 +############################################################ +# Abschluss +############################################################ + +Write-EnterpriseLog ` + + -Level INFO ` + + -Message "Installer beendet" + + + +Write-AuditEvent ` + + -Action "Installer beendet" ` + + -Status "SUCCESS" + + + +############################################################ +# Ende Install-VeeamEnterprise.ps1 +############################################################ \ No newline at end of file diff --git a/VEEAM-INSTTALL/Modules/CORE/Bootstrap.psm1 b/VEEAM-INSTTALL/Modules/CORE/Bootstrap.psm1 new file mode 100644 index 0000000..e05270c --- /dev/null +++ b/VEEAM-INSTTALL/Modules/CORE/Bootstrap.psm1 @@ -0,0 +1,595 @@ +<# + --------------------------------------------------------------------------- + Module......: Bootstrap.psm1 + Projekt.....: Veeam Enterprise Installer + Version.....: 2.0.0 + Autor.......: ChatGPT & Benutzer + PowerShell..: 5.1 + --------------------------------------------------------------------------- + + Beschreibung + + Initialisiert das komplette Installationsprojekt. + + Dieses Modul + + • bestimmt alle Projektpfade + • erstellt die Arbeitsverzeichnisse + • initialisiert globale Variablen + • legt Standardwerte fest + • erkennt das Betriebssystem + • stellt Informationen allen Modulen bereit + + Dieses Modul MUSS zuerst geladen werden. + +#> + +Set-StrictMode -Version Latest + +#region Script Variablen + +$Script:ProjectName = "Veeam Enterprise Installer" +$Script:ProjectVersion = "2.0.0" + +$Script:RootPath = $null +$Script:ModulePath = $null +$Script:ConfigPath = $null +$Script:ResourcePath = $null +$Script:ReportPath = $null +$Script:LogPath = $null +$Script:TempPath = $null + +$Script:LogFile = $null +$Script:TranscriptFile = $null + +$Script:Configuration = $null + +#endregion + +############################################################ +# Get-ProjectRoot +############################################################ + +function Get-ProjectRoot { + + <# + .SYNOPSIS + + Ermittelt den Projektordner. + + #> + + if($PSScriptRoot) + { + Split-Path $PSScriptRoot -Parent + } + else + { + Split-Path $MyInvocation.MyCommand.Path -Parent + } + +} + +############################################################ +# Initialize-Paths +############################################################ + +function Initialize-Paths { + + <# + .SYNOPSIS + + Initialisiert sämtliche Projektpfade. + + #> + + $Script:RootPath = + Get-ProjectRoot + + $Script:ModulePath = + Join-Path ` + $RootPath ` + "Modules" + + $Script:ConfigPath = + Join-Path ` + $RootPath ` + "Config" + + $Script:ResourcePath = + Join-Path ` + $RootPath ` + "Resources" + + $Script:ReportPath = + Join-Path ` + $RootPath ` + "Reports" + + $Script:LogPath = + Join-Path ` + $RootPath ` + "Logs" + + $Script:TempPath = + Join-Path ` + $RootPath ` + "Temp" + + $Script:LogFile = + Join-Path ` + $LogPath ` + "Install.log" + + $Script:TranscriptFile = + Join-Path ` + $LogPath ` + "Transcript.log" + +} + +############################################################ +# New-ProjectDirectory +############################################################ + +function New-ProjectDirectory { + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + if(Test-Path $Path) + { + return + } + + New-Item ` + -Path $Path ` + -ItemType Directory ` + -Force | Out-Null + +} + +############################################################ +# Initialize-Directories +############################################################ + +function Initialize-Directories { + + <# + .SYNOPSIS + + Erstellt alle Projektverzeichnisse. + + #> + + $Folders = @( + + $ModulePath, + $ConfigPath, + $ResourcePath, + $ReportPath, + $LogPath, + $TempPath + + ) + + foreach($Folder in $Folders) + { + + New-ProjectDirectory ` + -Path $Folder + + } + +} +#Beginn PART 2 +############################################################ +# Get-OperatingSystem +############################################################ + +function Get-OperatingSystem { + + <# + .SYNOPSIS + Liefert Informationen zum Betriebssystem. + #> + + try { + + Get-CimInstance ` + Win32_OperatingSystem + + } + catch { + + throw "Betriebssystem konnte nicht ermittelt werden." + + } + +} + +############################################################ +# Get-BuildNumber +############################################################ + +function Get-BuildNumber { + + <# + .SYNOPSIS + Liefert die Windows Buildnummer. + #> + + (Get-OperatingSystem).BuildNumber + +} + +############################################################ +# Get-PowerShellVersion +############################################################ + +function Get-PowerShellVersion { + + <# + .SYNOPSIS + Liefert die installierte PowerShell Version. + #> + + $PSVersionTable.PSVersion + +} + +############################################################ +# Test-Administrator +############################################################ + +function Test-Administrator { + + <# + .SYNOPSIS + Prüft Administratorrechte. + #> + + $Identity = + [Security.Principal.WindowsIdentity]::GetCurrent() + + $Principal = + New-Object Security.Principal.WindowsPrincipal($Identity) + + return $Principal.IsInRole( + [Security.Principal.WindowsBuiltInRole]::Administrator + ) + +} + +############################################################ +# Test-SupportedOperatingSystem +############################################################ + +function Test-SupportedOperatingSystem { + + <# + .SYNOPSIS + Unterstützt Windows Server 2022 und 2025. + #> + + $OS = Get-OperatingSystem + + $Caption = $OS.Caption + + if( + $Caption -match "Windows Server 2022" -or + $Caption -match "Windows Server 2025" + ) + { + return $true + } + + return $false + +} + +############################################################ +# Get-ComputerInformation +############################################################ + +function Get-ComputerInformation { + + <# + .SYNOPSIS + Erstellt ein Objekt mit Basisinformationen. + #> + + $OS = Get-OperatingSystem + + [PSCustomObject]@{ + + ComputerName = $env:COMPUTERNAME + + Domain = $env:USERDOMAIN + + User = $env:USERNAME + + OperatingSystem = $OS.Caption + + Version = $OS.Version + + Build = $OS.BuildNumber + + Architecture = $OS.OSArchitecture + + PowerShellVersion = Get-PowerShellVersion + + InstallDate = $OS.InstallDate + + LastBoot = $OS.LastBootUpTime + + } + +} + +############################################################ +# Test-Bootstrap +############################################################ + +function Test-Bootstrap { + + <# + .SYNOPSIS + Führt Grundprüfungen aus. + #> + + if(!(Test-Administrator)) + { + throw "Das Skript muss als Administrator ausgeführt werden." + } + + if(!(Test-SupportedOperatingSystem)) + { + throw "Nur Windows Server 2022 und 2025 werden unterstützt." + } + + if((Get-PowerShellVersion).Major -lt 5) + { + throw "PowerShell 5.1 oder neuer wird benötigt." + } + +} +#Beginn PART 3 +############################################################ +# Get-ProjectInformation +############################################################ + +function Get-ProjectInformation { + + <# + .SYNOPSIS + Liefert Projektinformationen. + #> + + [PSCustomObject]@{ + + ProjectName = $Script:ProjectName + Version = $Script:ProjectVersion + RootPath = $Script:RootPath + ModulePath = $Script:ModulePath + ConfigPath = $Script:ConfigPath + ResourcePath = $Script:ResourcePath + ReportPath = $Script:ReportPath + LogPath = $Script:LogPath + TempPath = $Script:TempPath + LogFile = $Script:LogFile + TranscriptFile = $Script:TranscriptFile + + } + +} + +############################################################ +# Show-BootstrapBanner +############################################################ + +function Show-BootstrapBanner { + + Write-Host "" + Write-Host "=========================================================" + Write-Host " Veeam Enterprise Installer" + Write-Host "=========================================================" + Write-Host "Version : $Script:ProjectVersion" + Write-Host "Computer : $env:COMPUTERNAME" + Write-Host "Benutzer : $env:USERNAME" + Write-Host "Projektpfad : $Script:RootPath" + Write-Host "=========================================================" + Write-Host "" + +} + +############################################################ +# Initialize-Bootstrap +############################################################ + +function Initialize-Bootstrap { + + <# + .SYNOPSIS + Initialisiert das komplette Framework. + #> + + Test-Bootstrap + + Initialize-Paths + + Initialize-Directories + + $Info = Get-ProjectInformation + + Write-Host "" + Write-Host "Projekt initialisiert" + + Write-Host "Root : $($Info.RootPath)" + Write-Host "Config : $($Info.ConfigPath)" + Write-Host "Logs : $($Info.LogPath)" + Write-Host "Reports : $($Info.ReportPath)" + Write-Host "Temp : $($Info.TempPath)" + + Show-BootstrapBanner + +} + +############################################################ +# Get-EnvironmentSummary +############################################################ + +function Get-EnvironmentSummary { + + $Computer = Get-ComputerInformation + + [PSCustomObject]@{ + + ProjectVersion = $Script:ProjectVersion + + ComputerName = $Computer.ComputerName + + Domain = $Computer.Domain + + User = $Computer.User + + OperatingSystem = $Computer.OperatingSystem + + Build = $Computer.Build + + Architecture = $Computer.Architecture + + PowerShell = $Computer.PowerShellVersion + + RootPath = $Script:RootPath + + LogPath = $Script:LogPath + + ReportPath = $Script:ReportPath + + TempPath = $Script:TempPath + + } + +} + +############################################################ +# Reset-Bootstrap +############################################################ + +function Reset-Bootstrap { + + $Script:Configuration = $null + +} +#Beginn PART 4 +############################################################ +# Get-ProjectPaths +############################################################ + +function Get-ProjectPaths { + + <# + .SYNOPSIS + Gibt alle Projektpfade zurück. + #> + + return [PSCustomObject]@{ + + Root = $Script:RootPath + Modules = $Script:ModulePath + Config = $Script:ConfigPath + Resources = $Script:ResourcePath + Reports = $Script:ReportPath + Logs = $Script:LogPath + Temp = $Script:TempPath + LogFile = $Script:LogFile + Transcript = $Script:TranscriptFile + + } + +} + +############################################################ +# Set-ProjectConfiguration +############################################################ + +function Set-ProjectConfiguration { + + param( + [Parameter(Mandatory)] + [psobject]$Configuration + ) + + $Script:Configuration = $Configuration + +} + +############################################################ +# Get-ProjectConfiguration +############################################################ + +function Get-ProjectConfiguration { + + return $Script:Configuration + +} + +############################################################ +# Test-ProjectInitialized +############################################################ + +function Test-ProjectInitialized { + + if([string]::IsNullOrWhiteSpace($Script:RootPath)) + { + return $false + } + + if(!(Test-Path $Script:RootPath)) + { + return $false + } + + return $true + +} + +############################################################ +# Initialize beim Import NICHT automatisch ausführen +############################################################ + +# Die Initialisierung erfolgt ausschließlich +# über Initialize-Bootstrap() im Hauptskript. + +############################################################ +# Exportierte Funktionen +############################################################ + +Export-ModuleMember ` + -Function ` + Initialize-Bootstrap, + Test-Bootstrap, + Test-Administrator, + Test-SupportedOperatingSystem, + Get-OperatingSystem, + Get-BuildNumber, + Get-PowerShellVersion, + Get-ComputerInformation, + Get-ProjectInformation, + Get-ProjectPaths, + Get-EnvironmentSummary, + Set-ProjectConfiguration, + Get-ProjectConfiguration, + Test-ProjectInitialized, + Reset-Bootstrap + +############################################################ +# Ende Bootstrap.psm1 +############################################################ + diff --git a/VEEAM-INSTTALL/Modules/CORE/Configuration.psm1 b/VEEAM-INSTTALL/Modules/CORE/Configuration.psm1 new file mode 100644 index 0000000..520f41c --- /dev/null +++ b/VEEAM-INSTTALL/Modules/CORE/Configuration.psm1 @@ -0,0 +1,1283 @@ +<# + --------------------------------------------------------------------------- + Module......: Configuration.psm1 + Projekt.....: Veeam Enterprise Installer + Version.....: 2.0.0 + + Beschreibung + + Verwaltung aller JSON-Konfigurationsdateien. + + Funktionen: + + • JSON laden + • Konfiguration prüfen + • Standardwerte setzen + • Konfiguration bereitstellen + • SQL / Domain / Logging Einstellungen laden + +---------------------------------------------------------------------------#> + +Set-StrictMode -Version Latest + + +#region Variablen + +$Script:ConfigurationData = @{} + +$Script:ConfigurationLoaded = $false + +#endregion + + +############################################################ +# Read-JsonFile +############################################################ + +function Read-JsonFile { + + <# + .SYNOPSIS + Liest eine JSON-Datei. + #> + + param( + + [Parameter(Mandatory)] + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + + throw "Konfigurationsdatei nicht gefunden: $Path" + + } + + + try + { + + $Content = + Get-Content ` + -Path $Path ` + -Raw ` + -Encoding UTF8 + + + return ( + $Content | + ConvertFrom-Json + ) + + } + catch + { + + throw ` + "Fehler beim Lesen der JSON Datei: $Path" + + } + +} + + +############################################################ +# Test-JsonFile +############################################################ + +function Test-JsonFile { + + <# + .SYNOPSIS + Prüft JSON Datei. + #> + + + param( + + [Parameter(Mandatory)] + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + return $false + } + + + try + { + + Get-Content ` + $Path ` + -Raw | + + ConvertFrom-Json | + + Out-Null + + + return $true + + } + catch + { + + return $false + + } + +} + + +############################################################ +# Get-ConfigurationPath +############################################################ + +function Get-ConfigurationPath { + + param( + + [Parameter(Mandatory)] + [string]$FileName + + ) + + + $Paths = + Get-ProjectPaths + + + Join-Path ` + $Paths.Config ` + $FileName + +} +#Beginn PART2 +############################################################ +# Import-VeeamConfiguration +############################################################ + +function Import-VeeamConfiguration { + + <# + .SYNOPSIS + Lädt die Hauptkonfiguration. + #> + + + $File = + Get-ConfigurationPath ` + -FileName "VeeamConfig.json" + + + Write-Verbose ` + "Lade Veeam Konfiguration" + + + if(!(Test-JsonFile $File)) + { + + throw ` + "VeeamConfig.json ist nicht vorhanden oder ungültig." + + } + + + Read-JsonFile ` + -Path $File + +} + +############################################################ +# Import-SQLConfiguration +############################################################ + +function Import-SQLConfiguration { + + <# + .SYNOPSIS + Lädt SQL Einstellungen. + #> + + + $File = + Get-ConfigurationPath ` + -FileName "SQLConfig.json" + + + if(!(Test-JsonFile $File)) + { + + throw ` + "SQLConfig.json ist nicht vorhanden oder ungültig." + + } + + + Read-JsonFile ` + -Path $File + +} + +############################################################ +# Import-DomainConfiguration +############################################################ + +function Import-DomainConfiguration { + + <# + .SYNOPSIS + Lädt Domänenkonfiguration. + #> + + + $File = + Get-ConfigurationPath ` + -FileName "DomainConfig.json" + + + if(!(Test-JsonFile $File)) + { + + Write-Warning ` + "Keine DomainConfig.json gefunden." + + return $null + + } + + + Read-JsonFile ` + -Path $File + +} + +############################################################ +# Import-LoggingConfiguration +############################################################ + +function Import-LoggingConfiguration { + + <# + .SYNOPSIS + Lädt Logging Einstellungen. + #> + + + $File = + Get-ConfigurationPath ` + -FileName "LoggingConfig.json" + + + if(!(Test-JsonFile $File)) + { + + return $null + + } + + + Read-JsonFile ` + -Path $File + +} + +############################################################ +# Import-PluginConfiguration +############################################################ + +function Import-PluginConfiguration { + + <# + .SYNOPSIS + Lädt Plugin Einstellungen. + #> + + + $File = + Get-ConfigurationPath ` + -FileName "Plugins.json" + + + if(!(Test-JsonFile $File)) + { + + return $null + + } + + + Read-JsonFile ` + -Path $File + +} +#Beginn PART 3 +############################################################ +# Import-AllConfiguration +############################################################ + +function Import-AllConfiguration { + + <# + .SYNOPSIS + Lädt alle Konfigurationsdateien. + #> + + + Write-Host "Lade Konfiguration..." + + + $Configuration = [ordered]@{} + + + # + # Hauptkonfiguration + # + + $Configuration.Veeam = + + Import-VeeamConfiguration + + + + # + # SQL + # + + $Configuration.SQL = + + Import-SQLConfiguration + + + + # + # Domain + # + + $Configuration.Domain = + + Import-DomainConfiguration + + + + # + # Logging + # + + $Configuration.Logging = + + Import-LoggingConfiguration + + + + # + # Plugins + # + + $Configuration.Plugins = + + Import-PluginConfiguration + + + + $Script:ConfigurationData = + + [PSCustomObject]$Configuration + + + + $Script:ConfigurationLoaded = $true + + + + Write-Host ` + "Konfiguration erfolgreich geladen." + + + return $Script:ConfigurationData + +} + +############################################################ +# Get-Configuration +############################################################ + +function Get-Configuration { + + <# + .SYNOPSIS + Liefert die komplette Konfiguration. + #> + + + if(!$Script:ConfigurationLoaded) + { + + throw ` + "Konfiguration wurde noch nicht geladen." + + } + + + return $Script:ConfigurationData + +} + +############################################################ +# Test-ConfigurationLoaded +############################################################ + +function Test-ConfigurationLoaded { + + + return $Script:ConfigurationLoaded + +} + +############################################################ +# Set-Configuration +############################################################ + +function Set-Configuration { + + + param( + + [Parameter(Mandatory)] + + [psobject]$Configuration + + ) + + + $Script:ConfigurationData = + $Configuration + + + $Script:ConfigurationLoaded = + $true + + +} + +############################################################ +# Clear-Configuration +############################################################ + +function Clear-Configuration { + + + $Script:ConfigurationData = + @{} + + $Script:ConfigurationLoaded = + $false + + +} +#Beginn PART 4 +############################################################ +# Get-ConfigurationValue +############################################################ + +function Get-ConfigurationValue { + + <# + .SYNOPSIS + Liest einen Wert aus der Konfiguration. + + .DESCRIPTION + Unterstützt Punktnotation. + + Beispiel: + SQL.Instance + + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(!$Script:ConfigurationLoaded) + { + + throw ` + "Konfiguration wurde nicht geladen." + + } + + + $Value = + $Script:ConfigurationData + + + + foreach($Part in $Path.Split(".")) + { + + if($null -eq $Value.$Part) + { + + return $null + + } + + + $Value = + $Value.$Part + + } + + + return $Value + +} + + +############################################################ +# Set-ConfigurationValue +############################################################ + +function Set-ConfigurationValue { + + + <# + .SYNOPSIS + Ändert einen Konfigurationswert. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path, + + + [Parameter(Mandatory)] + + $Value + + ) + + + $Parts = + $Path.Split(".") + + + $Object = + $Script:ConfigurationData + + + + for($i=0; $i -lt $Parts.Count-1; $i++) + { + + $Object = + $Object.($Parts[$i]) + + } + + + $Object.($Parts[-1]) = + $Value + + +} + + +############################################################ +# Test-RequiredConfiguration +############################################################ + +function Test-RequiredConfiguration { + + + <# + .SYNOPSIS + Prüft Pflichtwerte. + #> + + + param( + + [string[]]$RequiredValues + + ) + + + $Missing = @() + + + + foreach($ValuePath in $RequiredValues) + { + + $Value = + Get-ConfigurationValue ` + -Path $ValuePath + + + if( + $null -eq $Value -or + [string]::IsNullOrWhiteSpace( + [string]$Value + ) + ) + { + + $Missing += $ValuePath + + } + + } + + + + if($Missing.Count -gt 0) + { + + return [PSCustomObject]@{ + + Valid = $false + + Missing = $Missing + + } + + } + + + + return [PSCustomObject]@{ + + Valid = $true + + Missing = @() + + } + +} + +############################################################ +# Add-ConfigurationDefault +############################################################ + +function Add-ConfigurationDefault { + + + <# + .SYNOPSIS + Fügt Standardwerte hinzu. + #> + + + param( + + [string]$Path, + + $Value + + ) + + + $Existing = + Get-ConfigurationValue ` + -Path $Path + + + + if($null -eq $Existing) + { + + Set-ConfigurationValue ` + -Path $Path ` + -Value $Value + + } + + +} +#Beginn PART 5 +############################################################ +# Test-VeeamConfiguration +############################################################ + +function Test-VeeamConfiguration { + + <# + .SYNOPSIS + Prüft Veeam spezifische Konfiguration. + #> + + + $Required = @( + + "Veeam.Version", + "Veeam.InstallPath", + "Veeam.Source" + + ) + + + Test-RequiredConfiguration ` + -RequiredValues $Required + +} + +############################################################ +# Test-SQLConfiguration +############################################################ + +function Test-SQLConfiguration { + + <# + .SYNOPSIS + Prüft SQL Einstellungen. + #> + + + $Required = @( + + "SQL.Server", + "SQL.Instance", + "SQL.Database" + + ) + + + Test-RequiredConfiguration ` + -RequiredValues $Required + +} + +############################################################ +# Test-DomainConfiguration +############################################################ + +function Test-DomainConfiguration { + + + <# + .SYNOPSIS + Prüft Domänenkonfiguration. + #> + + + $Domain = + Get-ConfigurationValue ` + -Path "Domain.Enabled" + + + + if($Domain -eq $false) + { + + return [PSCustomObject]@{ + + Valid = $true + + Message = + "Keine Domänenintegration aktiviert." + + } + + } + + + + $Required = @( + + "Domain.Name", + "Domain.ServiceAccount" + + ) + + + Test-RequiredConfiguration ` + -RequiredValues $Required + +} + +############################################################ +# Test-PluginConfiguration +############################################################ + +function Test-PluginConfiguration { + + + <# + .SYNOPSIS + Prüft Plugin Einstellungen. + #> + + + $Plugins = + + Get-ConfigurationValue ` + -Path "Plugins" + + + + if($null -eq $Plugins) + { + + return [PSCustomObject]@{ + + Valid = $true + + Message = + "Keine Plugin-Konfiguration vorhanden." + + } + + } + + + return [PSCustomObject]@{ + + Valid = $true + + Plugins = $Plugins + + } + + +} + +############################################################ +# Test-PathConfiguration +############################################################ + +function Test-PathConfiguration { + + + <# + .SYNOPSIS + Prüft Installationspfade. + #> + + + $Paths = @( + + "Veeam.InstallPath", + "Veeam.CatalogPath", + "Veeam.TempPath" + + ) + + + $Result = @() + + + foreach($Path in $Paths) + { + + $Value = + Get-ConfigurationValue ` + -Path $Path + + + + if($null -ne $Value) + { + + $Result += [PSCustomObject]@{ + + Path = $Value + + Exists = + Test-Path $Value + + } + + } + + } + + + return $Result + +} + +############################################################ +# Validate-Configuration +############################################################ + +function Validate-Configuration { + + + <# + .SYNOPSIS + Gesamte Konfiguration prüfen. + #> + + + $Results = [ordered]@{} + + + + $Results.Veeam = + Test-VeeamConfiguration + + + + $Results.SQL = + Test-SQLConfiguration + + + + $Results.Domain = + Test-DomainConfiguration + + + + $Results.Plugins = + Test-PluginConfiguration + + + + $Results.Paths = + Test-PathConfiguration + + + + return [PSCustomObject]$Results + +} +#Beginn PART 6 +############################################################ +# Get-ConfigurationSummary +############################################################ + +function Get-ConfigurationSummary { + + <# + .SYNOPSIS + Erstellt eine Übersicht der geladenen Konfiguration. + #> + + + if(!$Script:ConfigurationLoaded) + { + + throw ` + "Keine Konfiguration geladen." + + } + + + [PSCustomObject]@{ + + Loaded = + $Script:ConfigurationLoaded + + + Sections = + $Script:ConfigurationData.PSObject.Properties.Name + + + LoadTime = + Get-Date + + } + +} + + +############################################################ +# Export-Configuration +############################################################ + +function Export-Configuration { + + <# + .SYNOPSIS + Exportiert die aktuelle Konfiguration. + #> + + + param( + + [string]$Path + + ) + + + if([string]::IsNullOrWhiteSpace($Path)) + { + + $Path = + Join-Path ` + (Get-ProjectPaths).Reports ` + "ConfigurationExport.json" + + } + + + $Script:ConfigurationData | + + ConvertTo-Json ` + -Depth 10 | + + Set-Content ` + -Path $Path ` + -Encoding UTF8 + + + return $Path + +} + + +############################################################ +# Import-ConfigurationFromFile +############################################################ + +function Import-ConfigurationFromFile { + + <# + .SYNOPSIS + Lädt eine komplette Konfiguration aus einer Datei. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + $Data = + Read-JsonFile ` + -Path $Path + + + Set-Configuration ` + -Configuration $Data + + + return $Data + +} + + +############################################################ +# Test-ConfigurationIntegrity +############################################################ + +function Test-ConfigurationIntegrity { + + + <# + .SYNOPSIS + Prüft Grundstruktur. + #> + + + if(!$Script:ConfigurationLoaded) + { + + return $false + + } + + + if($null -eq $Script:ConfigurationData) + { + + return $false + + } + + + return $true + +} +############################################################ +# Get-VeeamConfig +############################################################ + +function Get-VeeamConfig { + + + <# + .SYNOPSIS + Lädt zentrale Veeam Konfiguration aus JSON. + #> + + + param( + + [string]$Path = (Join-Path ( Split-Path $PSScriptRoot -Parent )"Config\VeeamConfig.json") + + ) + + + if(!(Test-Path $Path)) + { + + throw ` + + "Konfigurationsdatei nicht gefunden: $Path" + + } + + + + $Content = + + Get-Content ` + + -Path $Path ` + + -Raw + + + + $Configuration = + + $Content | + + ConvertFrom-Json + + + + return $Configuration + +} + + + +############################################################ +# Test-VeeamConfig +############################################################ + +function Test-VeeamConfig { + + + <# + .SYNOPSIS + Prüft Konfigurationswerte. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Configuration + + ) + + + [PSCustomObject]@{ + + + VeeamDefined = + + ( + ![string]::IsNullOrWhiteSpace( + $Configuration.Veeam.Version + ) + ) + + + + SQLDefined = + + ( + ![string]::IsNullOrWhiteSpace( + $Configuration.SQL.Server + ) + ) + + + + RepositoryDefined = + + ( + ![string]::IsNullOrWhiteSpace( + $Configuration.Repository.Path + ) + ) + + + + BackupJobDefined = + + ( + ![string]::IsNullOrWhiteSpace( + $Configuration.BackupJob.Name + ) + ) + + + + Valid = + + $true + + + + Checked = + + Get-Date + + } + +} + +############################################################ +# Export Module Functions +############################################################ + +Export-ModuleMember ` + -Function ` + Read-JsonFile, + Test-JsonFile, + Get-ConfigurationPath, + Import-VeeamConfiguration, + Import-SQLConfiguration, + Import-DomainConfiguration, + Import-LoggingConfiguration, + Import-PluginConfiguration, + Import-AllConfiguration, + Get-Configuration, + Test-ConfigurationLoaded, + Set-Configuration, + Clear-Configuration, + Get-ConfigurationValue, + Set-ConfigurationValue, + Test-RequiredConfiguration, + Add-ConfigurationDefault, + Test-VeeamConfiguration, + Test-SQLConfiguration, + Test-DomainConfiguration, + Test-PluginConfiguration, + Test-PathConfiguration, + Validate-Configuration, + Get-ConfigurationSummary, + Export-Configuration, + Import-ConfigurationFromFile, + Test-ConfigurationIntegrity + + +############################################################ +# Ende Configuration.psm1 +############################################################ diff --git a/VEEAM-INSTTALL/Modules/CORE/DryRun.psm1 b/VEEAM-INSTTALL/Modules/CORE/DryRun.psm1 new file mode 100644 index 0000000..518b668 --- /dev/null +++ b/VEEAM-INSTTALL/Modules/CORE/DryRun.psm1 @@ -0,0 +1,645 @@ +<# +.SYNOPSIS + + Dry-Run Funktionen für Veeam Enterprise Installer. + + +.DESCRIPTION + + Simuliert Installationsschritte ohne Änderungen. + + +.VERSION + + 1.0.0 + +#> + + +Set-StrictMode -Version Latest + + + +############################################################ +# Variablen +############################################################ + + +$Script:DryRunVersion = + + "1.0.0" + + + +$Script:DryRunEnabled = + + $true + + + +############################################################ +# Get-DryRunStatus +############################################################ + +function Get-DryRunStatus { + + + <# + .SYNOPSIS + Liefert Dry-Run Status. + #> + + + [PSCustomObject]@{ + + + Enabled = + + $Script:DryRunEnabled + + + + Mode = + + "Simulation" + + + + Version = + + $Script:DryRunVersion + + + + Time = + + Get-Date + + } + +} + + + +############################################################ +# Enable-DryRunMode +############################################################ + +function Enable-DryRunMode { + + + <# + .SYNOPSIS + Aktiviert Dry-Run. + #> + + + $Script:DryRunEnabled = + + $true + + + + return $true + +} + + + +############################################################ +# Disable-DryRunMode +############################################################ + +function Disable-DryRunMode { + + + <# + .SYNOPSIS + Deaktiviert Dry-Run. + #> + + + $Script:DryRunEnabled = + + $false + + + + return $true + +} +#Beginn PART 2 +############################################################ +# Invoke-DryRunAction +############################################################ + +function Invoke-DryRunAction { + + + <# + .SYNOPSIS + Simuliert eine Aktion. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Action, + + + [hashtable]$Parameters + + ) + + + [PSCustomObject]@{ + + + Action = + + $Action + + + + Parameters = + + $Parameters + + + + Executed = + + $false + + + + Mode = + + "DryRun" + + + + Message = + + "Aktion wurde nur simuliert." + + + + Time = + + Get-Date + + } + +} + + + +############################################################ +# Test-DryRunInstallation +############################################################ + +function Test-DryRunInstallation { + + + <# + .SYNOPSIS + Simuliert Veeam Installation. + #> + + + param( + + [string]$SourcePath, + + + [string]$SQLServer, + + + [string]$Database + + ) + + + Invoke-DryRunAction ` + + -Action "Install Veeam Backup & Replication" ` + + -Parameters @{ + + + Source = + + $SourcePath + + + + SQLServer = + + $SQLServer + + + + Database = + + $Database + + + } + +} + + + +############################################################ +# Test-DryRunRepository +############################################################ + +function Test-DryRunRepository { + + + <# + .SYNOPSIS + Simuliert Repository Erstellung. + #> + + + param( + + [string]$Name, + + + [string]$Path + + ) + + + Invoke-DryRunAction ` + + -Action "Create Backup Repository" ` + + -Parameters @{ + + + Name = + + $Name + + + + Path = + + $Path + + + } + +} +#Beginn PART 3 +############################################################ +# Test-DryRunBackupJob +############################################################ + +function Test-DryRunBackupJob { + + + <# + .SYNOPSIS + Simuliert Backup Job Erstellung. + #> + + + param( + + [string]$Name, + + + [string]$Repository, + + + [int]$RetentionDays = 14 + + ) + + + Invoke-DryRunAction ` + + -Action "Create Backup Job" ` + + -Parameters @{ + + + JobName = + + $Name + + + + Repository = + + $Repository + + + + RetentionDays = + + $RetentionDays + + + } + +} + + + +############################################################ +# Invoke-DryRunPipeline +############################################################ + +function Invoke-DryRunPipeline { + + + <# + .SYNOPSIS + Simuliert komplette Installation. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Configuration + + ) + + + $Results = @() + + + + $Results += + + Test-DryRunInstallation ` + + -SourcePath "Simulation" + + + + $Results += + + Test-DryRunRepository ` + + -Name $Configuration.RepositoryName ` + + -Path $Configuration.RepositoryPath + + + + $Results += + + Test-DryRunBackupJob ` + + -Name $Configuration.BackupJobName ` + + -Repository $Configuration.RepositoryName ` + + -RetentionDays $Configuration.RetentionDays + + + + return $Results + +} + + + +############################################################ +# Get-DryRunReport + +############################################################ + +function Get-DryRunReport { + + + <# + .SYNOPSIS + Erstellt Dry-Run Bericht. + #> + + + param( + + [Parameter(Mandatory)] + + [array]$Results + + ) + + + [PSCustomObject]@{ + + + Mode = + + "DryRun" + + + + Actions = + + $Results.Count + + + + Details = + + $Results + + + + Created = + + Get-Date + + } + +} +#Beginn PART 4 +############################################################ +# Save-DryRunReport +############################################################ + +function Save-DryRunReport { + + + <# + .SYNOPSIS + Speichert Dry-Run Bericht. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Report, + + + [string]$Path = + + "C:\ProgramData\VeeamInstaller\Reports" + + ) + + + + if(!(Test-Path $Path)) + { + + New-Item ` + + -Path $Path ` + + -ItemType Directory ` + + -Force | + + Out-Null + + } + + + + $File = + + Join-Path ` + + $Path ` + + ( + "DryRun_" + + + ( + Get-Date ` + -Format "yyyyMMdd_HHmmss" + ) + + + ".json" + ) + + + + $Report | + + ConvertTo-Json ` + + -Depth 10 | + + Out-File ` + + -FilePath $File ` + + -Encoding UTF8 + + + + return $File + +} + + + +############################################################ +# Test-DryRunConfiguration +############################################################ + +function Test-DryRunConfiguration { + + + <# + .SYNOPSIS + Prüft Dry-Run Konfiguration. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Configuration + + ) + + + [PSCustomObject]@{ + + + RepositoryDefined = + + ( + ![string]::IsNullOrWhiteSpace( + $Configuration.RepositoryPath + ) + ) + + + + DatabaseDefined = + + ( + ![string]::IsNullOrWhiteSpace( + $Configuration.Database + ) + ) + + + + JobDefined = + + ( + ![string]::IsNullOrWhiteSpace( + $Configuration.BackupJobName + ) + ) + + + + Valid = + + $true + + + + Checked = + + Get-Date + + } + +} +#Beginn PART 5 +############################################################ +# Export Module Functions +############################################################ + +Export-ModuleMember ` + -Function ` + Get-DryRunStatus, + Enable-DryRunMode, + Disable-DryRunMode, + Invoke-DryRunAction, + Test-DryRunInstallation, + Test-DryRunRepository, + Test-DryRunBackupJob, + Invoke-DryRunPipeline, + Get-DryRunReport, + Save-DryRunReport, + Test-DryRunConfiguration + + +############################################################ +# Ende DryRun.psm1 +############################################################ diff --git a/VEEAM-INSTTALL/Modules/CORE/Logging.psm1 b/VEEAM-INSTTALL/Modules/CORE/Logging.psm1 new file mode 100644 index 0000000..ef9b9ce --- /dev/null +++ b/VEEAM-INSTTALL/Modules/CORE/Logging.psm1 @@ -0,0 +1,1701 @@ +<# + --------------------------------------------------------------------------- + Module......: Logging.psm1 + Projekt.....: Veeam Enterprise Installer + Version.....: 2.0.0 + + Beschreibung + + Zentrales Logging-Modul. + + Funktionen + + • Textlog + • Transcript + • Konsolenausgabe + • Farbige Statusmeldungen + • Logrotation + • Archivierung + • Debug Logging + • Fehlerprotokollierung + • Veeam Setup Log Kopie + +---------------------------------------------------------------------------#> + +Set-StrictMode -Version Latest + +#region Script Variablen + +$Script:LogFile = $null +$Script:TranscriptFile = $null +$Script:LogLevel = "INFO" + +#endregion + +############################################################ +# Initialize-Logging +############################################################ + +function Initialize-Logging { + + <# + .SYNOPSIS + Initialisiert das Logging. + #> + + $Paths = Get-ProjectPaths + + $Script:LogFile = $Paths.LogFile + $Script:TranscriptFile = $Paths.Transcript + + if (!(Test-Path $Paths.Logs)) { + New-Item -Path $Paths.Logs -ItemType Directory -Force | Out-Null + } + + if (!(Test-Path $Script:LogFile)) { + New-Item -Path $Script:LogFile -ItemType File -Force | Out-Null + } + +} + +############################################################ +# Get-TimeStamp +############################################################ + +function Get-TimeStamp { + + Get-Date -Format "yyyy-MM-dd HH:mm:ss" + +} + +############################################################ +# Write-Log +############################################################ + +function Write-Log { + + param( + + [Parameter(Mandatory)] + [string]$Message, + + [ValidateSet("INFO","WARN","ERROR","SUCCESS","DEBUG")] + [string]$Level = "INFO" + + ) + + $Time = Get-TimeStamp + + $Entry = "[{0}] [{1}] {2}" -f $Time,$Level,$Message + + Add-Content ` + -Path $Script:LogFile ` + -Value $Entry + + switch($Level) + { + + "INFO" { + + Write-Host $Entry -ForegroundColor White + + } + + "WARN" { + + Write-Host $Entry -ForegroundColor Yellow + + } + + "ERROR" { + + Write-Host $Entry -ForegroundColor Red + + } + + "SUCCESS" { + + Write-Host $Entry -ForegroundColor Green + + } + + "DEBUG" { + + Write-Host $Entry -ForegroundColor Cyan + + } + + } + +} + +############################################################ +# Write-Info +############################################################ + +function Write-Info { + + param([string]$Message) + + Write-Log ` + -Message $Message ` + -Level INFO + +} + +############################################################ +# Write-Success +############################################################ + +function Write-Success { + + param([string]$Message) + + Write-Log ` + -Message $Message ` + -Level SUCCESS + +} +#Beginn PART 2 +############################################################ +# Write-Warning +############################################################ + +function Write-WarningLog { + + <# + .SYNOPSIS + Schreibt eine Warnung. + #> + + param( + [Parameter(Mandatory)] + [string]$Message + ) + + Write-Log ` + -Message $Message ` + -Level WARN + +} + +############################################################ +# Write-Error +############################################################ + +function Write-ErrorLog { + + <# + .SYNOPSIS + Schreibt einen Fehler. + #> + + param( + [Parameter(Mandatory)] + [string]$Message + ) + + Write-Log ` + -Message $Message ` + -Level ERROR + +} + +############################################################ +# Write-Debug +############################################################ + +function Write-DebugLog { + + <# + .SYNOPSIS + Schreibt Debugmeldungen. + #> + + param( + [Parameter(Mandatory)] + [string]$Message + ) + + if($Script:LogLevel -eq "DEBUG") + { + Write-Log ` + -Message $Message ` + -Level DEBUG + } + +} + +############################################################ +# Write-Separator +############################################################ + +function Write-Separator { + + Write-Host "" + Write-Host ("-" * 70) + + Add-Content ` + -Path $Script:LogFile ` + -Value ("-" * 70) + +} + +############################################################ +# Write-Section +############################################################ + +function Write-Section { + + param( + [Parameter(Mandatory)] + [string]$Title + ) + + Write-Separator + + Write-Info $Title + + Write-Separator + +} + +############################################################ +# Write-Banner +############################################################ + +function Write-Banner { + + Write-Host "" + Write-Host "===============================================================" -ForegroundColor Cyan + Write-Host " Veeam Enterprise Installer v2.0" -ForegroundColor Cyan + Write-Host "===============================================================" -ForegroundColor Cyan + Write-Host "" + + Add-Content ` + -Path $Script:LogFile ` + -Value "===============================================================" + + Add-Content ` + -Path $Script:LogFile ` + -Value "Veeam Enterprise Installer gestartet" + + Add-Content ` + -Path $Script:LogFile ` + -Value "===============================================================" + +} + +############################################################ +# Start-TranscriptLogging +############################################################ + +function Start-TranscriptLogging { + + <# + .SYNOPSIS + Startet PowerShell Transcript. + #> + + try + { + + if(Test-Path $Script:TranscriptFile) + { + Remove-Item ` + $Script:TranscriptFile ` + -Force + } + + Start-Transcript ` + -Path $Script:TranscriptFile ` + -Force | Out-Null + + Write-Success "Transcript gestartet." + + } + catch + { + + Write-WarningLog ` + "Transcript konnte nicht gestartet werden." + + } + +} + +############################################################ +# Stop-TranscriptLogging +############################################################ + +function Stop-TranscriptLogging { + + <# + .SYNOPSIS + Beendet das Transcript. + #> + + try + { + + Stop-Transcript | Out-Null + + } + catch + { + + # Bereits beendet + + } + +} +#Beginn PART3 +############################################################ +# Rotate-Logs +############################################################ + +function Rotate-Logs { + + <# + .SYNOPSIS + Löscht alte Logdateien. + #> + + param( + + [int]$RetentionDays = 30 + + ) + + $Paths = Get-ProjectPaths + + Write-Info "Prüfe Logrotation..." + + Get-ChildItem ` + -Path $Paths.Logs ` + -Filter "*.log" ` + -ErrorAction SilentlyContinue | + + Where-Object { + + $_.LastWriteTime -lt (Get-Date).AddDays(-$RetentionDays) + + } | + + ForEach-Object { + + Write-Info "Lösche alte Logdatei: $($_.Name)" + + Remove-Item ` + $_.FullName ` + -Force ` + -ErrorAction SilentlyContinue + + } + +} + +############################################################ +# Archive-Logs +############################################################ + +function Archive-Logs { + + <# + .SYNOPSIS + Verschiebt Logs in ein Archiv. + #> + + $Paths = Get-ProjectPaths + + $ArchiveFolder = Join-Path ` + $Paths.Logs ` + "Archive" + + if(!(Test-Path $ArchiveFolder)) + { + + New-Item ` + -Path $ArchiveFolder ` + -ItemType Directory ` + -Force | Out-Null + + } + + $TimeStamp = + Get-Date -Format "yyyyMMdd_HHmmss" + + $Destination = + Join-Path ` + $ArchiveFolder ` + "Logs_$TimeStamp" + + New-Item ` + -Path $Destination ` + -ItemType Directory ` + -Force | Out-Null + + Get-ChildItem ` + $Paths.Logs ` + -Filter "*.log" | + + Where-Object { + + $_.Name -notmatch "Transcript" + + } | + + Copy-Item ` + -Destination $Destination ` + -Force + + Write-Success "Logs archiviert." + +} + +############################################################ +# Compress-Logs +############################################################ + +function Compress-Logs { + + <# + .SYNOPSIS + Erstellt ZIP Archiv. + #> + + $Paths = Get-ProjectPaths + + $ArchiveFolder = + Join-Path ` + $Paths.Logs ` + "Archive" + + $ZipFile = + Join-Path ` + $ArchiveFolder ` + ("Logs_{0}.zip" -f (Get-Date -Format "yyyyMMdd_HHmmss")) + + Add-Type ` + -AssemblyName ` + System.IO.Compression.FileSystem + + [System.IO.Compression.ZipFile]::CreateFromDirectory( + + $Paths.Logs, + + $ZipFile + + ) + + Write-Success "ZIP Archiv erstellt." + +} + +############################################################ +# Clear-Logs +############################################################ + +function Clear-Logs { + + <# + .SYNOPSIS + Löscht alle Logdateien. + #> + + $Paths = Get-ProjectPaths + + Get-ChildItem ` + $Paths.Logs ` + -Filter "*.log" | + + Remove-Item ` + -Force ` + -ErrorAction SilentlyContinue + + Write-Success "Logdateien gelöscht." + +} + +############################################################ +# Copy-VeeamSetupLogs +############################################################ + +function Copy-VeeamSetupLogs { + + <# + .SYNOPSIS + Kopiert die Veeam Setup Logs. + #> + + $Source = + + "C:\ProgramData\Veeam\Setup\Temp" + + if(!(Test-Path $Source)) + { + + Write-WarningLog ` + "Keine Veeam Setup Logs gefunden." + + return + + } + + $Destination = + + Join-Path ` + (Get-ProjectPaths).Logs ` + "VeeamSetup" + + if(!(Test-Path $Destination)) + { + + New-Item ` + $Destination ` + -ItemType Directory ` + -Force | Out-Null + + } + + Copy-Item ` + "$Source\*" ` + $Destination ` + -Recurse ` + -Force + + Write-Success ` + "Veeam Setup Logs kopiert." + +} +#Beginn PART 4 +############################################################ +# Write-ExceptionLog +############################################################ + +function Write-ExceptionLog { + + <# + .SYNOPSIS + Schreibt eine Exception vollständig ins Log. + #> + + param( + + [Parameter(Mandatory)] + [System.Exception]$Exception + + ) + + $Message = @" + +Exception: +----------- +Message : $($Exception.Message) + +Type : +$($Exception.GetType().FullName) + +StackTrace : +$($Exception.StackTrace) + +"@ + + Write-Log ` + -Message $Message ` + -Level ERROR + +} + +############################################################ +# Write-ProgressLog +############################################################ + +function Write-ProgressLog { + + <# + .SYNOPSIS + Schreibt Fortschritt einer Aktion. + #> + + param( + + [Parameter(Mandatory)] + [string]$Action, + + [Parameter(Mandatory)] + [string]$Status + + ) + + + Write-Log ` + -Message "$Action : $Status" ` + -Level INFO + +} + +############################################################ +# Start-OperationTimer +############################################################ + +function Start-OperationTimer { + + <# + .SYNOPSIS + Startet Zeitmessung. + #> + + param( + + [string]$Name = "Operation" + + ) + + $Timer = [System.Diagnostics.Stopwatch]::StartNew() + + return [PSCustomObject]@{ + + Name = $Name + + Timer = $Timer + + Start = Get-Date + + } + +} + +############################################################ +# Stop-OperationTimer +############################################################ + +function Stop-OperationTimer { + + <# + .SYNOPSIS + Beendet Zeitmessung. + #> + + param( + + [Parameter(Mandatory)] + $TimerObject + + ) + + + $TimerObject.Timer.Stop() + + + $Elapsed = + $TimerObject.Timer.Elapsed + + + Write-Success ( + + "{0} abgeschlossen. Dauer: {1}" -f + $TimerObject.Name, + $Elapsed + + ) + + + return $Elapsed + +} + +############################################################ +# Write-ModuleHeader +############################################################ + +function Write-ModuleHeader { + + <# + .SYNOPSIS + Schreibt Modulstart. + #> + + param( + + [Parameter(Mandatory)] + [string]$ModuleName + + ) + + + Write-Section ` + "Starte Modul: $ModuleName" + + +} + +############################################################ +# Write-ModuleFooter +############################################################ + +function Write-ModuleFooter { + + <# + .SYNOPSIS + Schreibt Modulende. + #> + + param( + + [Parameter(Mandatory)] + [string]$ModuleName, + + [string]$Status = "OK" + + ) + + + Write-Success ( + + "Modul beendet: {0} Status: {1}" -f + $ModuleName, + $Status + + ) + + + Write-Separator + +} + +############################################################ +# Write-ConfigurationValue +############################################################ + +function Write-ConfigurationValue { + + <# + .SYNOPSIS + Protokolliert Konfigurationswerte. + #> + + param( + + [string]$Name, + + [string]$Value + + ) + + + if([string]::IsNullOrWhiteSpace($Value)) + { + + $Value = "" + + } + + + Write-DebugLog ( + + "{0} = {1}" -f + $Name, + $Value + + ) + +} +#Beginn PART 5 +############################################################ +# Set-LogLevel +############################################################ + +function Set-LogLevel { + + <# + .SYNOPSIS + Setzt den Detailgrad des Loggings. + #> + + param( + + [ValidateSet( + "INFO", + "DEBUG" + )] + + [string]$Level = "INFO" + + ) + + + $Script:LogLevel = $Level + + + Write-Info ` + "Log-Level gesetzt: $Level" + +} + +############################################################ +# Get-LogLevel +############################################################ + +function Get-LogLevel { + + return $Script:LogLevel + +} + +############################################################ +# Enable-DebugLogging +############################################################ + +function Enable-DebugLogging { + + Set-LogLevel ` + -Level DEBUG + +} + +############################################################ +# Disable-DebugLogging +############################################################ + +function Disable-DebugLogging { + + Set-LogLevel ` + -Level INFO + +} + +############################################################ +# Invoke-ErrorHandler +############################################################ + +function Invoke-ErrorHandler { + + <# + .SYNOPSIS + Zentrale Fehlerbehandlung. + #> + + param( + + [Parameter(Mandatory)] + [System.Management.Automation.ErrorRecord] + $ErrorRecord + + ) + + + $Message = @" + +Unbehandelter Fehler + +Message: +$($ErrorRecord.Exception.Message) + +Kategorie: +$($ErrorRecord.CategoryInfo) + +Position: +$($ErrorRecord.InvocationInfo.PositionMessage) + +"@ + + + Write-Log ` + -Message $Message ` + -Level ERROR + + +} + +############################################################ +# Register-GlobalErrorHandler +############################################################ + +function Register-GlobalErrorHandler { + + <# + .SYNOPSIS + Aktiviert globale Fehlerbehandlung. + #> + + + $Script:PreviousErrorActionPreference = + $ErrorActionPreference + + + $ErrorActionPreference = "Stop" + + + trap { + + Invoke-ErrorHandler ` + -ErrorRecord $_ + + continue + + } + + + Write-Info ` + "Globale Fehlerbehandlung aktiviert." + +} + +############################################################ +# Save-InstallationState +############################################################ + +function Save-InstallationState { + + <# + .SYNOPSIS + Speichert Installationsstatus. + #> + + param( + + [Parameter(Mandatory)] + [string]$Step, + + [Parameter(Mandatory)] + [ValidateSet( + "START", + "RUNNING", + "SUCCESS", + "FAILED" + )] + + [string]$Status + + ) + + + $StateFile = Join-Path ( + + (Get-ProjectPaths).Temp + + ) "InstallationState.json" + + + $State = [PSCustomObject]@{ + + Step = $Step + + Status = $Status + + Computer = $env:COMPUTERNAME + + User = $env:USERNAME + + Date = Get-Date + + } + + + $State | + + ConvertTo-Json | + + Set-Content ` + -Path $StateFile ` + -Encoding UTF8 + + + Write-DebugLog ` + "Installationsstatus gespeichert: $Step / $Status" + +} + +############################################################ +# Get-InstallationState +############################################################ + +function Get-InstallationState { + + <# + .SYNOPSIS + Liest gespeicherten Status. + #> + + + $StateFile = Join-Path ( + + (Get-ProjectPaths).Temp + + ) "InstallationState.json" + + + if(!(Test-Path $StateFile)) + { + + return $null + + } + + + Get-Content ` + $StateFile ` + -Raw | + + ConvertFrom-Json + +} + +############################################################ +# Remove-InstallationState +############################################################ + +function Remove-InstallationState { + + + $StateFile = Join-Path ( + + (Get-ProjectPaths).Temp + + ) "InstallationState.json" + + + if(Test-Path $StateFile) + { + + Remove-Item ` + $StateFile ` + -Force + + } + + +} +#Beginn PART 6 +############################################################ +# Test-LogFile +############################################################ + +function Test-LogFile { + + <# + .SYNOPSIS + Prüft ob Logdatei verfügbar ist. + #> + + if([string]::IsNullOrWhiteSpace($Script:LogFile)) + { + return $false + } + + + return (Test-Path $Script:LogFile) + +} + +############################################################ +# Get-LogInformation +############################################################ + +function Get-LogInformation { + + <# + .SYNOPSIS + Liefert Logging Informationen. + #> + + + [PSCustomObject]@{ + + LogFile = $Script:LogFile + + Transcript = $Script:TranscriptFile + + LogLevel = $Script:LogLevel + + LogAvailable = Test-LogFile + + } + +} + +############################################################ +# Close-Logging +############################################################ + +function Close-Logging { + + <# + .SYNOPSIS + Beendet Logging sauber. + #> + + + Write-Info ` + "Logging wird beendet." + + + try + { + + Stop-TranscriptLogging + + } + catch + { + + } + + +} +############################################################ +# Erweiterte Funktionen für Logging +############################################################ +############################################################ +# Enterprise Logging +############################################################ + +$Script:LogDirectory = + + "C:\ProgramData\VeeamInstaller\Logs" + + + +############################################################ +# Initialize-EnterpriseLog +############################################################ + +function Initialize-EnterpriseLog { + + + param( + + [string]$Name = "VeeamInstall" + + ) + + + if(!(Test-Path $Script:LogDirectory)) + { + + New-Item ` + -Path $Script:LogDirectory ` + -ItemType Directory ` + -Force | + + Out-Null + + } + + + + $Script:LogFile = + + Join-Path ` + $Script:LogDirectory ` + + ( + $Name + + "_" + + ( + Get-Date ` + -Format "yyyyMMdd_HHmmss" + ) + + ".log" + ) + + + + New-Item ` + -Path $Script:LogFile ` + -ItemType File ` + -Force | + + Out-Null + + + + return $Script:LogFile + +} +############################################################ +# Write-EnterpriseLog +############################################################ + +function Write-EnterpriseLog { + + + <# + .SYNOPSIS + Schreibt Enterprise Log Einträge. + #> + + + param( + + [ValidateSet( + "INFO", + "WARNING", + "ERROR", + "DEBUG" + )] + + [string]$Level = "INFO", + + + + [Parameter(Mandatory)] + + [string]$Message + + ) + + + + if(!$Script:LogFile) + { + + Initialize-EnterpriseLog | + + Out-Null + + } + + + + $Entry = + + [PSCustomObject]@{ + + + Time = + + Get-Date + + + + Level = + + $Level + + + + Computer = + + $env:COMPUTERNAME + + + + User = + + $env:USERNAME + + + + Message = + + $Message + + } + + + + $Line = + + ( + $Entry.Time.ToString( + "yyyy-MM-dd HH:mm:ss" + ) + ) + + + " [" + + + $Entry.Level + + + "] " + + + $Entry.Message + + + + Add-Content ` + + -Path $Script:LogFile ` + + -Value $Line + + + + return $Entry + +} + + + +############################################################ +# Write-AuditEvent +############################################################ + +function Write-AuditEvent { + + + <# + .SYNOPSIS + Schreibt strukturiertes Audit Event. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Action, + + + + [string]$Status = "SUCCESS", + + + + [hashtable]$Data + + ) + + + $AuditDirectory = + + "C:\ProgramData\VeeamInstaller\Audit" + + + + if(!(Test-Path $AuditDirectory)) + { + + New-Item ` + + -Path $AuditDirectory ` + + -ItemType Directory ` + + -Force | + + Out-Null + + } + + + + $AuditFile = + + Join-Path ` + + $AuditDirectory ` + + "Audit.json" + + + + $Event = + + [PSCustomObject]@{ + + + Time = + + Get-Date + + + + Action = + + $Action + + + + Status = + + $Status + + + + Data = + + $Data + + } + + + + $Event | + + ConvertTo-Json ` + + -Depth 8 | + + Add-Content ` + + -Path $AuditFile + + + + return $Event + +} +############################################################ +# Write-ExceptionLog +############################################################ + +function Write-ExceptionLog { + + + <# + .SYNOPSIS + Speichert Fehlerdetails. + #> + + + param( + + [Parameter(Mandatory)] + + [System.Exception]$Exception, + + + [string]$Context = "Unknown" + + ) + + + + $ErrorEntry = + + [PSCustomObject]@{ + + + Time = + + Get-Date + + + + Level = + + "ERROR" + + + + Context = + + $Context + + + + Message = + + $Exception.Message + + + + Type = + + $Exception.GetType().FullName + + + + StackTrace = + + $Exception.StackTrace + + } + + + + Write-EnterpriseLog ` + + -Level ERROR ` + + -Message ( + + "$Context - $($Exception.Message)" + + ) + + + + $ErrorFile = + + Join-Path ` + + $Script:LogDirectory ` + + "Errors.json" + + + + $ErrorEntry | + + ConvertTo-Json ` + + -Depth 10 | + + Add-Content ` + + -Path $ErrorFile + + + + return $ErrorEntry + +} + + + +############################################################ +# Start-InstallPhase +############################################################ + +function Start-InstallPhase { + + + <# + .SYNOPSIS + Protokolliert Installationsphase. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name + + ) + + + + Write-EnterpriseLog ` + + -Level INFO ` + + -Message ( + + "START PHASE: " + $Name + + ) + + + + Write-AuditEvent ` + + -Action ( + + "Start Phase: " + $Name + + ) + + + +} + + + +############################################################ +# Complete-InstallPhase +############################################################ + +function Complete-InstallPhase { + + + <# + .SYNOPSIS + Beendet Installationsphase. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name, + + + [string]$Status = "SUCCESS" + + ) + + + + Write-EnterpriseLog ` + + -Level INFO ` + + -Message ( + + "END PHASE: " + $Name + + ) + + + + Write-AuditEvent ` + + -Action ( + + "End Phase: " + $Name + + ) + + -Status $Status + +} + + +############################################################ +# Export Module Functions +############################################################ + +Export-ModuleMember ` + -Function ` + Initialize-Logging, + Write-Log, + Write-Info, + Write-Success, + Write-WarningLog, + Write-ErrorLog, + Write-DebugLog, + Write-Separator, + Write-Section, + Write-Banner, + Start-TranscriptLogging, + Stop-TranscriptLogging, + Rotate-Logs, + Archive-Logs, + Compress-Logs, + Clear-Logs, + Copy-VeeamSetupLogs, + Write-ExceptionLog, + Write-ProgressLog, + Start-OperationTimer, + Stop-OperationTimer, + Write-ModuleHeader, + Write-ModuleFooter, + Write-ConfigurationValue, + Set-LogLevel, + Get-LogLevel, + Enable-DebugLogging, + Disable-DebugLogging, + Invoke-ErrorHandler, + Register-GlobalErrorHandler, + Save-InstallationState, + Get-InstallationState, + Remove-InstallationState, + Test-LogFile, + Get-LogInformation, + Initialize-EnterpriseLog, + Write-EnterpriseLog, + Write-AuditEvent, + Write-ExceptionLog, + Start-InstallPhase, + Complete-InstallPhase + Close-Logging + + +############################################################ +# Ende Logging.psm1 +############################################################ diff --git a/VEEAM-INSTTALL/Modules/CORE/SQL.psm1 b/VEEAM-INSTTALL/Modules/CORE/SQL.psm1 new file mode 100644 index 0000000..a698759 --- /dev/null +++ b/VEEAM-INSTTALL/Modules/CORE/SQL.psm1 @@ -0,0 +1,1383 @@ +<# + --------------------------------------------------------------------------- + Module......: SQL.psm1 + Projekt.....: Veeam Enterprise Installer + Version.....: 2.0.0 + + Beschreibung + + SQL Verwaltung für Veeam Installation. + + Unterstützt: + + • SQL Instanzprüfung + • SQL Verbindung + • Serviceprüfung + • Datenbankprüfung + • Benutzerprüfung + • Datenbankbereitstellung + + Zielumgebung: + + SQL Server 2022 Standard + Instanz VEEAMSQLSERVER + +---------------------------------------------------------------------------#> + +Set-StrictMode -Version Latest + + +#region Variablen + +$Script:SQLVersion = "2.0.0" + +$Script:DefaultInstance = "VEEAMSQLSERVER" + +#endregion + + +############################################################ +# Get-SQLServiceName +############################################################ + +function Get-SQLServiceName { + + <# + .SYNOPSIS + Ermittelt SQL Dienstnamen. + #> + + + param( + + [string]$Instance = + $Script:DefaultInstance + + ) + + + if($Instance -eq "MSSQLSERVER") + { + + return "MSSQLSERVER" + + } + + + return "MSSQL`$$Instance" + +} + + +############################################################ +# Get-SQLService + +############################################################ + +function Get-SQLService { + + + <# + .SYNOPSIS + Liefert SQL Dienst. + #> + + + param( + + [string]$Instance = + $Script:DefaultInstance + + ) + + + $ServiceName = + + Get-SQLServiceName ` + -Instance $Instance + + + + try + { + + Get-Service ` + -Name $ServiceName ` + -ErrorAction Stop + + } + catch + { + + return $null + + } + +} + + +############################################################ +# Test-SQLService + +############################################################ + +function Test-SQLService { + + + <# + .SYNOPSIS + Prüft SQL Dienst. + #> + + + param( + + [string]$Instance = + $Script:DefaultInstance + + ) + + + $Service = + + Get-SQLService ` + -Instance $Instance + + + + if($null -eq $Service) + { + + return $false + + } + + + return ( + + $Service.Status -eq "Running" + + ) + +} +#Beginn PART 2 +############################################################ +# Get-SQLInstances +############################################################ + +function Get-SQLInstances { + + <# + .SYNOPSIS + Listet SQL Instanzen auf dem Server. + #> + + + $RegistryPaths = @( + + "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\Instance Names\SQL", + + "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Microsoft SQL Server\Instance Names\SQL" + + ) + + + $Instances = @() + + + + foreach($Path in $RegistryPaths) + { + + if(Test-Path $Path) + { + + $Data = + + Get-ItemProperty ` + -Path $Path + + + + foreach($Property in $Data.PSObject.Properties) + { + + if( + $Property.Name ` + -notmatch "^PS" + ) + { + + $Instances += [PSCustomObject]@{ + + Name = + $Property.Name + + + InstanceID = + $Property.Value + + } + + } + + } + + } + + } + + + return $Instances + +} + + +############################################################ +# Test-SQLInstanceExists +############################################################ + +function Test-SQLInstanceExists { + + + param( + + [string]$Instance = + $Script:DefaultInstance + + ) + + + $Instances = + + Get-SQLInstances + + + + foreach($Item in $Instances) + { + + if( + $Item.Name ` + -eq $Instance + ) + { + + return $true + + } + + } + + + return $false + +} + + +############################################################ +# Get-SQLVersion +############################################################ + +function Get-SQLVersion { + + + <# + .SYNOPSIS + Liest SQL Server Version. + #> + + + param( + + [string]$Instance = + $Script:DefaultInstance + + ) + + + $Path = + + "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server" + + + if(!(Test-Path $Path)) + { + + return $null + + } + + + Get-ChildItem ` + $Path | + + Where-Object { + + $_.PSChildName ` + -like "MSSQL*" + + } | + + Select-Object ` + PSChildName + +} + + +############################################################ +# Get-SQLPort + +############################################################ + +function Get-SQLPort { + + + <# + .SYNOPSIS + Liest TCP Port der Instanz. + #> + + + param( + + [string]$Instance = + $Script:DefaultInstance + + ) + + + $Instances = + + Get-SQLInstances + + + + $Target = + + $Instances | + + Where-Object { + + $_.Name -eq $Instance + + } + + + + if($null -eq $Target) + { + + return $null + + } + + + $PortPath = + + "HKLM:\SOFTWARE\Microsoft\Microsoft SQL Server\$($Target.InstanceID)\MSSQLServer\SuperSocketNetLib\Tcp\IPAll" + + + + if(Test-Path $PortPath) + { + + Get-ItemProperty ` + $PortPath | + + Select-Object ` + TcpPort, + TcpDynamicPorts + + } + +} +#Beginn PART 3 +############################################################ +# New-SQLConnectionString +############################################################ + +function New-SQLConnectionString { + + <# + .SYNOPSIS + Erstellt SQL Connection String. + #> + + + param( + + [string]$Server = + $env:COMPUTERNAME, + + + [string]$Instance = + $Script:DefaultInstance, + + + [string]$Database = + "master" + + ) + + + return ( + + "Server=$Server\$Instance;" + + "Database=$Database;" + + "Integrated Security=True;" + + "TrustServerCertificate=True;" + + ) + +} + + +############################################################ +# Test-SQLConnection + +############################################################ + +function Test-SQLConnection { + + + <# + .SYNOPSIS + Prüft SQL Verbindung. + #> + + + param( + + [string]$Server = + $env:COMPUTERNAME, + + + [string]$Instance = + $Script:DefaultInstance + + ) + + + $ConnectionString = + + New-SQLConnectionString ` + -Server $Server ` + -Instance $Instance + + + + try + { + + $Connection = + + New-Object ` + System.Data.SqlClient.SqlConnection( + $ConnectionString + ) + + + $Connection.Open() + + + $Connection.Close() + + + return $true + + } + catch + { + + return $false + + } + +} + + +############################################################ +# Invoke-SQLQuery +############################################################ + +function Invoke-SQLQuery { + + + <# + .SYNOPSIS + Führt SQL Query aus. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Query, + + + [string]$Database = + "master", + + + [string]$Server = + $env:COMPUTERNAME, + + + [string]$Instance = + $Script:DefaultInstance + + ) + + + $ConnectionString = + + New-SQLConnectionString ` + -Server $Server ` + -Instance $Instance ` + -Database $Database + + + + $Connection = + + New-Object ` + System.Data.SqlClient.SqlConnection( + $ConnectionString + ) + + + $Command = + + $Connection.CreateCommand() + + + $Command.CommandText = + $Query + + + + try + { + + $Connection.Open() + + + $Adapter = + + New-Object ` + System.Data.SqlClient.SqlDataAdapter( + $Command + ) + + + $Table = + + New-Object ` + System.Data.DataTable + + + $Adapter.Fill($Table) | + + Out-Null + + + return $Table + + } + finally + { + + $Connection.Close() + + } + +} + + +############################################################ +# Get-SQLDatabases + +############################################################ + +function Get-SQLDatabases { + + + <# + .SYNOPSIS + Listet Datenbanken. + #> + + + Invoke-SQLQuery ` + + -Query " + SELECT + name, + database_id, + state_desc + FROM sys.databases + ORDER BY name + " + +} +#Beginn PART 4 +############################################################ +# Test-DatabaseExists +############################################################ + +function Test-DatabaseExists { + + + <# + .SYNOPSIS + Prüft ob Datenbank existiert. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$DatabaseName + + ) + + + $Result = + + Invoke-SQLQuery ` + + -Query " + + SELECT name + + FROM sys.databases + + WHERE name = '$DatabaseName' + + " + + + + return ( + + $null -ne $Result -and + $Result.Count -gt 0 + + ) + +} + + +############################################################ +# New-SQLDatabase +############################################################ + +function New-SQLDatabase { + + + <# + .SYNOPSIS + Erstellt SQL Datenbank. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$DatabaseName + + ) + + + if(Test-DatabaseExists $DatabaseName) + { + + return $false + + } + + + Invoke-SQLQuery ` + + -Query " + + CREATE DATABASE [$DatabaseName] + + " | Out-Null + + + + return ( + + Test-DatabaseExists ` + -DatabaseName $DatabaseName + + ) + +} + + +############################################################ +# Remove-SQLDatabase + +############################################################ + +function Remove-SQLDatabase { + + + <# + .SYNOPSIS + Löscht SQL Datenbank. + + Nur für Wartung/Test. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$DatabaseName + + ) + + + if(!(Test-DatabaseExists $DatabaseName)) + { + + return $false + + } + + + Invoke-SQLQuery ` + + -Query " + + ALTER DATABASE [$DatabaseName] + + SET SINGLE_USER + + WITH ROLLBACK IMMEDIATE; + + + DROP DATABASE [$DatabaseName]; + + " | Out-Null + + + + return $true + +} + + +############################################################ +# Get-DatabaseCollation + +############################################################ + +function Get-DatabaseCollation { + + + <# + .SYNOPSIS + Liest Datenbank Collation. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$DatabaseName + + ) + + + $Result = + + Invoke-SQLQuery ` + + -Database $DatabaseName ` + + -Query " + + SELECT + + DATABASEPROPERTYEX( + DB_NAME(), + 'Collation' + ) + AS Collation + + " + + + return $Result.Collation + +} + + +############################################################ +# Test-VeeamDatabase + +############################################################ + +function Test-VeeamDatabase { + + + <# + .SYNOPSIS + Prüft Veeam Datenbank. + #> + + + param( + + [string]$DatabaseName = + "VeeamBackup" + + ) + + + [PSCustomObject]@{ + + Name = + $DatabaseName + + + Exists = + Test-DatabaseExists ` + -DatabaseName $DatabaseName + + + Collation = + if( + Test-DatabaseExists ` + -DatabaseName $DatabaseName + ) + { + + Get-DatabaseCollation ` + -DatabaseName $DatabaseName + + } + else + { + + $null + + } + + } + +} +#Beginn PART 5 +############################################################ +# Test-SQLLoginExists +############################################################ + +function Test-SQLLoginExists { + + + <# + .SYNOPSIS + Prüft SQL Login. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$LoginName + + ) + + + $Result = + + Invoke-SQLQuery ` + + -Query " + + SELECT name + + FROM sys.server_principals + + WHERE name = '$LoginName' + + " + + + + return ( + + $null -ne $Result -and + $Result.Count -gt 0 + + ) + +} + + +############################################################ +# Get-SQLLogin + +############################################################ + +function Get-SQLLogin { + + + param( + + [Parameter(Mandatory)] + + [string]$LoginName + + ) + + + Invoke-SQLQuery ` + + -Query " + + SELECT + + name, + + type_desc, + + create_date + + FROM sys.server_principals + + WHERE name = '$LoginName' + + " + +} + + +############################################################ +# Test-DatabasePermission + +############################################################ + +function Test-DatabasePermission { + + + <# + .SYNOPSIS + Prüft Datenbankrechte. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$DatabaseName, + + + [Parameter(Mandatory)] + + [string]$UserName + + ) + + + $Result = + + Invoke-SQLQuery ` + + -Database $DatabaseName ` + + -Query " + + SELECT + + dp.name, + + dp.type_desc + + FROM + + sys.database_principals dp + + WHERE + + dp.name = '$UserName' + + " + + + + return $Result + +} + + +############################################################ +# Get-SQLConfigurationReport +############################################################ + +function Get-SQLConfigurationReport { + + + <# + .SYNOPSIS + Erstellt SQL Bericht. + #> + + + [PSCustomObject]@{ + + + Computer = + + $env:COMPUTERNAME + + + + Instance = + + $Script:DefaultInstance + + + + ServiceRunning = + + Test-SQLService + + + + Connection = + + Test-SQLConnection + + + + Databases = + + Get-SQLDatabases + + + + Timestamp = + + Get-Date + + } + +} + + +############################################################ +# Test-VeeamSQLPreparation + +############################################################ + +function Test-VeeamSQLPreparation { + + + <# + .SYNOPSIS + Komplette SQL Vorbereitung. + #> + + + $Report = [ordered]@{} + + + + $Report.Instance = + + Test-SQLInstanceExists + + + + $Report.Service = + + Test-SQLService + + + + $Report.Connection = + + Test-SQLConnection + + + + $Report.Database = + + Test-VeeamDatabase + + + + return ( + + [PSCustomObject]$Report + + ) + +} +#Beginn PART 6 +############################################################ +# Get-SQLServerInformation +############################################################ + +function Get-SQLServerInformation { + + + <# + .SYNOPSIS + Liefert SQL Server Informationen. + #> + + + $Result = + + Invoke-SQLQuery ` + + -Query " + + SELECT + + SERVERPROPERTY( + 'ServerName' + ) AS ServerName, + + + SERVERPROPERTY( + 'ProductVersion' + ) AS ProductVersion, + + + SERVERPROPERTY( + 'ProductLevel' + ) AS ProductLevel, + + + SERVERPROPERTY( + 'Edition' + ) AS Edition + + " + + + return $Result + +} + + +############################################################ +# Test-SQLVersionSupported +############################################################ + +function Test-SQLVersionSupported { + + + <# + .SYNOPSIS + Prüft SQL Version. + + Ziel: + SQL Server 2022 + #> + + + $Info = + + Get-SQLServerInformation + + + + if($null -eq $Info) + { + + return $false + + } + + + + return ( + + $Info.ProductVersion ` + -like "16.*" + + ) + +} + + +############################################################ +# Get-SQLEdition + +############################################################ + +function Get-SQLEdition { + + + $Info = + + Get-SQLServerInformation + + + + if($null -eq $Info) + { + + return $null + + } + + + return $Info.Edition + +} + + +############################################################ +# Test-SQLConfiguration + + +############################################################ + +function Test-SQLConfiguration { + + + <# + .SYNOPSIS + Gesamte SQL Prüfung. + #> + + + [PSCustomObject]@{ + + + Instance = + + $Script:DefaultInstance + + + + Service = + + Test-SQLService + + + + Connection = + + Test-SQLConnection + + + + VersionSupported = + + Test-SQLVersionSupported + + + + Edition = + + Get-SQLEdition + + + + Database = + + Test-VeeamDatabase + + + + Time = + + Get-Date + + } + +} + + +############################################################ +# Get-SQLModuleInformation + +############################################################ + +function Get-SQLModuleInformation { + + + [PSCustomObject]@{ + + + Module = + + "SQL.psm1" + + + + Version = + + $Script:SQLVersion + + + + DefaultInstance = + + $Script:DefaultInstance + + + + Loaded = + + $true + + } + +} +#Beginn PART 7 +############################################################ +# Export Module Functions +############################################################ + +Export-ModuleMember ` + -Function ` + Get-SQLServiceName, + Get-SQLService, + Test-SQLService, + Get-SQLInstances, + Test-SQLInstanceExists, + Get-SQLVersion, + Get-SQLPort, + New-SQLConnectionString, + Test-SQLConnection, + Invoke-SQLQuery, + Get-SQLDatabases, + Test-DatabaseExists, + New-SQLDatabase, + Remove-SQLDatabase, + Get-DatabaseCollation, + Test-VeeamDatabase, + Test-SQLLoginExists, + Get-SQLLogin, + Test-DatabasePermission, + Get-SQLConfigurationReport, + Test-VeeamSQLPreparation, + Get-SQLServerInformation, + Test-SQLVersionSupported, + Get-SQLEdition, + Test-SQLConfiguration, + Get-SQLModuleInformation + + +############################################################ +# Ende SQL.psm1 +############################################################ diff --git a/VEEAM-INSTTALL/Modules/CORE/Security.psm1 b/VEEAM-INSTTALL/Modules/CORE/Security.psm1 new file mode 100644 index 0000000..921b232 --- /dev/null +++ b/VEEAM-INSTTALL/Modules/CORE/Security.psm1 @@ -0,0 +1,1281 @@ +<# + --------------------------------------------------------------------------- + Module......: Security.psm1 + Projekt.....: Veeam Enterprise Installer + Version.....: 2.0.0 + + Beschreibung + + Sicherheitsfunktionen für Installation und Betrieb. + + Funktionen: + + • Administratorprüfung + • Benutzerprüfung + • Gruppenprüfung + • Berechtigungen + • Credentials + • Zertifikate + +---------------------------------------------------------------------------#> + +Set-StrictMode -Version Latest + + +#region Variablen + +$Script:SecurityVersion = "2.0.0" + +#endregion + + +############################################################ +# Get-CurrentIdentity +############################################################ + +function Get-CurrentIdentity { + + <# + .SYNOPSIS + Liefert aktuellen Benutzer. + #> + + + [System.Security.Principal.WindowsIdentity]::GetCurrent() + +} + + +############################################################ +# Get-CurrentUserName +############################################################ + +function Get-CurrentUserName { + + + $Identity = + Get-CurrentIdentity + + + return $Identity.Name + +} + + +############################################################ +# Test-IsAdministrator +############################################################ + +function Test-IsAdministrator { + + <# + .SYNOPSIS + Prüft Administratorrechte. + #> + + + $Identity = + Get-CurrentIdentity + + + $Principal = + + New-Object ` + System.Security.Principal.WindowsPrincipal( + $Identity + ) + + + return ( + + $Principal.IsInRole( + [System.Security.Principal.WindowsBuiltInRole]::Administrator + ) + + ) + +} + + +############################################################ +# Test-UserExists +############################################################ + +function Test-UserExists { + + <# + .SYNOPSIS + Prüft lokales Konto. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$UserName + + ) + + + try + { + + Get-LocalUser ` + -Name $UserName ` + -ErrorAction Stop | + + Out-Null + + + return $true + + } + catch + { + + return $false + + } + +} + + +############################################################ +# Get-LocalGroupMembers +############################################################ + +function Get-LocalGroupMembers { + + + param( + + [Parameter(Mandatory)] + + [string]$GroupName + + ) + + + try + { + + Get-LocalGroupMember ` + -Group $GroupName + + } + catch + { + + return $null + + } + +} +#Beginn PART 2 +############################################################ +# Test-LocalGroupExists +############################################################ + +function Test-LocalGroupExists { + + <# + .SYNOPSIS + Prüft lokale Gruppe. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$GroupName + + ) + + + try + { + + Get-LocalGroup ` + -Name $GroupName ` + -ErrorAction Stop | + + Out-Null + + + return $true + + } + catch + { + + return $false + + } + +} + + +############################################################ +# Add-UserToLocalGroupSafe +############################################################ + +function Add-UserToLocalGroupSafe { + + <# + .SYNOPSIS + Fügt Benutzer zu Gruppe hinzu. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$User, + + + [Parameter(Mandatory)] + + [string]$Group + + ) + + + if(!(Test-LocalGroupExists $Group)) + { + + throw ` + "Lokale Gruppe nicht gefunden: $Group" + + } + + + $Existing = + + Get-LocalGroupMembers ` + -GroupName $Group + + + + if( + $Existing.Name ` + -notcontains $User + ) + { + + Add-LocalGroupMember ` + -Group $Group ` + -Member $User + + } + +} + + +############################################################ +# Remove-UserFromLocalGroupSafe +############################################################ + +function Remove-UserFromLocalGroupSafe { + + param( + + [Parameter(Mandatory)] + + [string]$User, + + + [Parameter(Mandatory)] + + [string]$Group + + ) + + + try + { + + Remove-LocalGroupMember ` + -Group $Group ` + -Member $User ` + -ErrorAction Stop + + } + catch + { + + # Benutzer nicht vorhanden + + } + +} + + +############################################################ +# Get-NTFSPermission + +############################################################ + +function Get-NTFSPermission { + + + <# + .SYNOPSIS + Liest NTFS Berechtigungen. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + + throw ` + "Pfad nicht gefunden: $Path" + + } + + + Get-Acl ` + -Path $Path + +} + + +############################################################ +# Set-NTFSPermission + +############################################################ + +function Set-NTFSPermission { + + + <# + .SYNOPSIS + Setzt NTFS Berechtigung. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path, + + + [Parameter(Mandatory)] + + [string]$Account, + + + [ValidateSet( + "Read", + "Modify", + "FullControl" + )] + + [string]$Permission = "Modify" + + ) + + + if(!(Test-Path $Path)) + { + + throw ` + "Pfad nicht gefunden: $Path" + + } + + + $ACL = + + Get-Acl ` + -Path $Path + + + + $Rule = + + New-Object ` + System.Security.AccessControl.FileSystemAccessRule( + + $Account, + + $Permission, + + "ContainerInherit,ObjectInherit", + + "None", + + "Allow" + + ) + + + + $ACL.AddAccessRule($Rule) + + + + Set-Acl ` + -Path $Path ` + -AclObject $ACL + +} +#Beginn PART 3 +############################################################ +# New-SecureCredential +############################################################ + +function New-SecureCredential { + + <# + .SYNOPSIS + Erstellt ein Credential Objekt. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$UserName, + + + [Parameter(Mandatory)] + + [SecureString]$Password + + ) + + + New-Object ` + System.Management.Automation.PSCredential( + $UserName, + $Password + ) + +} + + +############################################################ +# ConvertTo-SecurePassword + +############################################################ + +function ConvertTo-SecurePassword { + + <# + .SYNOPSIS + Wandelt Klartext in SecureString um. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Password + + ) + + + ConvertTo-SecureString ` + -String $Password ` + -AsPlainText ` + -Force + +} + + +############################################################ +# Export-SecureCredential + +############################################################ + +function Export-SecureCredential { + + + <# + .SYNOPSIS + Speichert Credential verschlüsselt. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCredential]$Credential, + + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + $Credential | + + Export-Clixml ` + -Path $Path + + + return $Path + +} + + +############################################################ +# Import-SecureCredential + +############################################################ + +function Import-SecureCredential { + + + <# + .SYNOPSIS + Lädt Credential. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + + throw ` + "Credential Datei nicht gefunden: $Path" + + } + + + Import-Clixml ` + -Path $Path + +} + + +############################################################ +# Test-DomainAccount + +############################################################ + +function Test-DomainAccount { + + + <# + .SYNOPSIS + Prüft Domänenkonto. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Account + + ) + + + try + { + + $User = + + New-Object ` + System.Security.Principal.NTAccount( + $Account + ) + + + $SID = + + $User.Translate( + [System.Security.Principal.SecurityIdentifier] + ) + + + return $true + + } + catch + { + + return $false + + } + +} + + +############################################################ +# Test-ServiceAccountFormat + +############################################################ + +function Test-ServiceAccountFormat { + + + <# + .SYNOPSIS + Prüft Kontoformat. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Account + + ) + + + return ( + + $Account -match "\\" + + ) + +} +#Beginn PART 4 +############################################################ +# Get-Certificate + +############################################################ + +function Get-Certificate { + + + <# + .SYNOPSIS + Sucht Zertifikate. + #> + + + param( + + [string]$Thumbprint, + + [string]$Store = + "Cert:\LocalMachine\My" + + ) + + + if($Thumbprint) + { + + return Get-ChildItem ` + -Path $Store | + + Where-Object { + + $_.Thumbprint ` + -eq $Thumbprint + + } + + } + + + Get-ChildItem ` + -Path $Store + +} + + +############################################################ +# Find-CertificateBySubject + +############################################################ + +function Find-CertificateBySubject { + + + <# + .SYNOPSIS + Sucht Zertifikat nach Name. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Subject, + + + [string]$Store = + "Cert:\LocalMachine\My" + + ) + + + Get-ChildItem ` + -Path $Store | + + Where-Object { + + $_.Subject ` + -like "*$Subject*" + + } + +} + + +############################################################ +# Test-CertificateValid + +############################################################ + +function Test-CertificateValid { + + + <# + .SYNOPSIS + Prüft Zertifikat. + #> + + + param( + + [Parameter(Mandatory)] + + [System.Security.Cryptography.X509Certificates.X509Certificate2] + $Certificate + + ) + + + $Now = + Get-Date + + + + return ( + + $Certificate.NotBefore -lt $Now -and + + $Certificate.NotAfter -gt $Now + + ) + +} + + +############################################################ +# Get-CertificateInformation + +############################################################ + +function Get-CertificateInformation { + + + param( + + [Parameter(Mandatory)] + + [System.Security.Cryptography.X509Certificates.X509Certificate2] + $Certificate + + ) + + + [PSCustomObject]@{ + + Subject = + $Certificate.Subject + + + Issuer = + $Certificate.Issuer + + + Thumbprint = + $Certificate.Thumbprint + + + NotBefore = + $Certificate.NotBefore + + + NotAfter = + $Certificate.NotAfter + + + DaysRemaining = + + ( + $Certificate.NotAfter - + (Get-Date) + ).Days + + + } + +} + + +############################################################ +# Import-CertificateSafe + +############################################################ + +function Import-CertificateSafe { + + + <# + .SYNOPSIS + Importiert Zertifikat. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path, + + + [string]$Store = + "Cert:\LocalMachine\My" + + ) + + + if(!(Test-Path $Path)) + { + + throw ` + "Zertifikat nicht gefunden: $Path" + + } + + + Import-Certificate ` + + -FilePath $Path ` + + -CertStoreLocation $Store + +} + + +############################################################ +# Export-CertificateSafe + +############################################################ + +function Export-CertificateSafe { + + + <# + .SYNOPSIS + Exportiert Zertifikat. + #> + + + param( + + [Parameter(Mandatory)] + + [System.Security.Cryptography.X509Certificates.X509Certificate2] + $Certificate, + + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + Export-Certificate ` + + -Cert $Certificate ` + + -FilePath $Path ` + + -Force + +} +#Beginn PART 5 +############################################################ +# Test-DirectoryPermission +############################################################ + +function Test-DirectoryPermission { + + <# + .SYNOPSIS + Prüft Verzeichnisrechte. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path, + + + [Parameter(Mandatory)] + + [string]$Account + + ) + + + if(!(Test-Path $Path)) + { + + return $false + + } + + + $ACL = + + Get-Acl ` + -Path $Path + + + + foreach($Entry in $ACL.Access) + { + + if( + $Entry.IdentityReference ` + -eq $Account + ) + { + + return $true + + } + + } + + + return $false + +} + + +############################################################ +# Test-AccountPermission + +############################################################ + +function Test-AccountPermission { + + + <# + .SYNOPSIS + Prüft mehrere Konten. + #> + + + param( + + [string[]]$Accounts + + ) + + + $Result = @() + + + foreach($Account in $Accounts) + { + + $Result += [PSCustomObject]@{ + + Account = + $Account + + + Exists = + Test-DomainAccount ` + -Account $Account + + + } + + } + + + return $Result + +} + + +############################################################ +# Get-SecuritySummary + +############################################################ + +function Get-SecuritySummary { + + + <# + .SYNOPSIS + Erstellt Sicherheitsübersicht. + #> + + + [PSCustomObject]@{ + + User = + Get-CurrentUserName + + + Administrator = + Test-IsAdministrator + + + Computer = + $env:COMPUTERNAME + + + Time = + Get-Date + + + Module = + "Security.psm1" + + + } + +} + + +############################################################ +# Protect-PasswordFile + +############################################################ + +function Protect-PasswordFile { + + + <# + .SYNOPSIS + Schützt Passwortdatei über NTFS. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + + return + + } + + + $ACL = + + Get-Acl ` + $Path + + + + $ACL.SetAccessRuleProtection( + $true, + $false + ) + + + Set-Acl ` + -Path $Path ` + -AclObject $ACL + +} + + +############################################################ +# Test-SecurityBaseline + +############################################################ + +function Test-SecurityBaseline { + + + <# + .SYNOPSIS + Grundlegende Sicherheitsprüfung. + #> + + + [PSCustomObject]@{ + + Administrator = + + Test-IsAdministrator + + + Computer = + + $env:COMPUTERNAME + + + User = + + Get-CurrentUserName + + + Time = + + Get-Date + + } + +} +#Beginn PART 6 +############################################################ +# Get-SecurityInformation +############################################################ + +function Get-SecurityInformation { + + <# + .SYNOPSIS + Liefert Modulinformationen. + #> + + + [PSCustomObject]@{ + + Module = + "Security.psm1" + + + Version = + $Script:SecurityVersion + + + Loaded = + $true + + + Computer = + $env:COMPUTERNAME + + + User = + Get-CurrentUserName + + } + +} + + +############################################################ +# Test-SecurityModule + +############################################################ + +function Test-SecurityModule { + + + <# + .SYNOPSIS + Prüft ob Modul funktioniert. + #> + + + [PSCustomObject]@{ + + Module = + "Security" + + + Status = + "OK" + + + Administrator = + Test-IsAdministrator + + + Timestamp = + Get-Date + + } + +} + + +############################################################ +# Export Module Functions +############################################################ + +Export-ModuleMember ` + -Function ` + + Get-CurrentIdentity, + Get-CurrentUserName, + Test-IsAdministrator, + Test-UserExists, + Get-LocalGroupMembers, + Test-LocalGroupExists, + Add-UserToLocalGroupSafe, + Remove-UserFromLocalGroupSafe, + Get-NTFSPermission, + Set-NTFSPermission, + New-SecureCredential, + ConvertTo-SecurePassword, + Export-SecureCredential, + Import-SecureCredential, + Test-DomainAccount, + Test-ServiceAccountFormat, + Get-Certificate, + Find-CertificateBySubject, + Test-CertificateValid, + Get-CertificateInformation, + Import-CertificateSafe, + Export-CertificateSafe, + Test-DirectoryPermission, + Test-AccountPermission, + Get-SecuritySummary, + Protect-PasswordFile, + Test-SecurityBaseline, + Get-SecurityInformation, + Test-SecurityModule + + +############################################################ +# Ende Security.psm1 +############################################################ diff --git a/VEEAM-INSTTALL/Modules/CORE/Utilities.psm1 b/VEEAM-INSTTALL/Modules/CORE/Utilities.psm1 new file mode 100644 index 0000000..4dd5b47 --- /dev/null +++ b/VEEAM-INSTTALL/Modules/CORE/Utilities.psm1 @@ -0,0 +1,1510 @@ +<# + --------------------------------------------------------------------------- + Module......: Utilities.psm1 + Projekt.....: Veeam Enterprise Installer + Version.....: 2.0.0 + + Beschreibung + + Allgemeine Hilfsfunktionen. + + Enthält: + + • Dateioperationen + • Hashprüfung + • Speicherprüfung + • Registry Funktionen + • Service Funktionen + • Netzwerkprüfung + • Versionsvergleich + +---------------------------------------------------------------------------#> + +Set-StrictMode -Version Latest + + +#region Variablen + +$Script:UtilityVersion = "2.0.0" + +#endregion + + +############################################################ +# Test-PathExists +############################################################ + +function Test-PathExists { + + <# + .SYNOPSIS + Prüft ob ein Pfad existiert. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + return ( + Test-Path ` + -Path $Path + ) + +} + + +############################################################ +# New-Folder +############################################################ + +function New-Folder { + + <# + .SYNOPSIS + Erstellt einen Ordner. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + + New-Item ` + -Path $Path ` + -ItemType Directory ` + -Force | + + Out-Null + + } + + + return $Path + +} + + +############################################################ +# Remove-FolderSafe +############################################################ + +function Remove-FolderSafe { + + <# + .SYNOPSIS + Löscht Ordner sicher. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(Test-Path $Path) + { + + Remove-Item ` + -Path $Path ` + -Recurse ` + -Force + + } + +} + + +############################################################ +# Copy-FileSafe +############################################################ + +function Copy-FileSafe { + + <# + .SYNOPSIS + Kopiert Dateien mit Prüfung. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Source, + + + [Parameter(Mandatory)] + + [string]$Destination + + ) + + + if(!(Test-Path $Source)) + { + + throw ` + "Quelldatei nicht gefunden: $Source" + + } + + + $TargetFolder = + Split-Path ` + $Destination ` + -Parent + + + if(!(Test-Path $TargetFolder)) + { + + New-Folder ` + -Path $TargetFolder + + } + + + Copy-Item ` + -Path $Source ` + -Destination $Destination ` + -Force + + + return ( + Test-Path $Destination + ) + +} +#Beginn PART 2 +############################################################ +# Get-FileHashValue +############################################################ + +function Get-FileHashValue { + + <# + .SYNOPSIS + Ermittelt den Hash einer Datei. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path, + + + [ValidateSet( + "SHA1", + "SHA256", + "SHA384", + "SHA512" + )] + + [string]$Algorithm = "SHA256" + + ) + + + if(!(Test-Path $Path)) + { + + throw ` + "Datei nicht gefunden: $Path" + + } + + + ( + Get-FileHash ` + -Path $Path ` + -Algorithm $Algorithm + ).Hash + +} + + +############################################################ +# Compare-FileHash +############################################################ + +function Compare-FileHash { + + <# + .SYNOPSIS + Vergleicht Dateihashes. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$File1, + + + [Parameter(Mandatory)] + + [string]$File2 + + ) + + + $Hash1 = + Get-FileHashValue ` + -Path $File1 + + + $Hash2 = + Get-FileHashValue ` + -Path $File2 + + + + return ( + $Hash1 -eq $Hash2 + ) + +} + + +############################################################ +# Get-FileInformation +############################################################ + +function Get-FileInformation { + + <# + .SYNOPSIS + Liefert Dateiinformationen. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + + return $null + + } + + + $File = + Get-Item ` + $Path + + + + [PSCustomObject]@{ + + Name = + $File.Name + + FullName = + $File.FullName + + SizeMB = + [math]::Round( + $File.Length / 1MB, + 2 + ) + + Created = + $File.CreationTime + + Modified = + $File.LastWriteTime + + Hash = + Get-FileHashValue ` + -Path $Path + + } + +} + + +############################################################ +# Get-DiskInformation +############################################################ + +function Get-DiskInformation { + + + <# + .SYNOPSIS + Liefert Laufwerksinformationen. + #> + + + Get-CimInstance ` + Win32_LogicalDisk ` + -Filter "DriveType=3" | + + Select-Object ` + + DeviceID, + + VolumeName, + + @{ + + Name="SizeGB" + + Expression={ + + [math]::Round( + $_.Size / 1GB, + 2 + ) + + } + + }, + + @{ + + Name="FreeGB" + + Expression={ + + [math]::Round( + $_.FreeSpace / 1GB, + 2 + ) + + } + + } + +} + + +############################################################ +# Test-FreeSpace +############################################################ + +function Test-FreeSpace { + + <# + .SYNOPSIS + Prüft freien Speicherplatz. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Drive, + + + [int]$MinimumGB = 20 + + ) + + + $Disk = + + Get-CimInstance ` + Win32_LogicalDisk ` + -Filter "DeviceID='$Drive'" + + + if($null -eq $Disk) + { + + return $false + + } + + + $FreeGB = + + $Disk.FreeSpace / 1GB + + + + return ( + + $FreeGB -ge $MinimumGB + + ) + +} +#Beginn PART 3 +############################################################ +# Get-RegistryValue +############################################################ + +function Get-RegistryValue { + + <# + .SYNOPSIS + Liest einen Registrywert. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path, + + + [Parameter(Mandatory)] + + [string]$Name + + ) + + + try + { + + $Item = + Get-ItemProperty ` + -Path $Path ` + -ErrorAction Stop + + + return $Item.$Name + + } + catch + { + + return $null + + } + +} + + +############################################################ +# Test-RegistryPath +############################################################ + +function Test-RegistryPath { + + <# + .SYNOPSIS + Prüft Registrypfad. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + return ( + Test-Path ` + -Path $Path + ) + +} + + +############################################################ +# Get-InstalledSoftware +############################################################ + +function Get-InstalledSoftware { + + <# + .SYNOPSIS + Listet installierte Programme. + #> + + + $RegistryPaths = @( + + "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*", + + "HKLM:\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" + + ) + + + foreach($RegistryPath in $RegistryPaths) + { + + if(Test-Path $RegistryPath) + { + + Get-ItemProperty ` + $RegistryPath | + + Where-Object { + + $_.DisplayName + + } | + + Select-Object ` + + DisplayName, + + DisplayVersion, + + Publisher, + + InstallDate + + } + + } + +} + + +############################################################ +# Test-SoftwareInstalled +############################################################ + +function Test-SoftwareInstalled { + + <# + .SYNOPSIS + Prüft ob Software installiert ist. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name + + ) + + + $Software = + + Get-InstalledSoftware + + + + foreach($Entry in $Software) + { + + if( + $Entry.DisplayName ` + -like "*$Name*" + ) + { + + return $true + + } + + } + + + return $false + +} + + +############################################################ +# Get-WindowsFeatureState +############################################################ + +function Get-WindowsFeatureState { + + <# + .SYNOPSIS + Prüft Windows Features. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$FeatureName + + ) + + + try + { + + Get-WindowsFeature ` + -Name $FeatureName + + } + catch + { + + return $null + + } + +} + + +############################################################ +# Test-WindowsFeatureInstalled +############################################################ + +function Test-WindowsFeatureInstalled { + + <# + .SYNOPSIS + Prüft Feature Status. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$FeatureName + + ) + + + $Feature = + + Get-WindowsFeatureState ` + -FeatureName $FeatureName + + + + if($null -eq $Feature) + { + + return $false + + } + + + return ( + + $Feature.InstallState ` + -eq "Installed" + + ) + +} +#Beginn PART 4 +############################################################ +# Get-ServiceInformation +############################################################ + +function Get-ServiceInformation { + + <# + .SYNOPSIS + Liefert Informationen zu einem Dienst. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name + + ) + + + try + { + + Get-Service ` + -Name $Name ` + -ErrorAction Stop + + } + catch + { + + return $null + + } + +} + + +############################################################ +# Test-ServiceExists +############################################################ + +function Test-ServiceExists { + + <# + .SYNOPSIS + Prüft ob Dienst vorhanden ist. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name + + ) + + + return ( + + $null -ne ( + Get-ServiceInformation ` + -Name $Name + ) + + ) + +} + + +############################################################ +# Test-ServiceRunning +############################################################ + +function Test-ServiceRunning { + + <# + .SYNOPSIS + Prüft Dienststatus. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name + + ) + + + $Service = + + Get-ServiceInformation ` + -Name $Name + + + + if($null -eq $Service) + { + + return $false + + } + + + return ( + + $Service.Status ` + -eq "Running" + + ) + +} + + +############################################################ +# Start-ServiceSafe +############################################################ + +function Start-ServiceSafe { + + <# + .SYNOPSIS + Startet Dienst sicher. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name + + ) + + + if(Test-ServiceExists $Name) + { + + Start-Service ` + -Name $Name ` + -ErrorAction Stop + + } + +} + + +############################################################ +# Stop-ServiceSafe +############################################################ + +function Stop-ServiceSafe { + + <# + .SYNOPSIS + Stoppt Dienst sicher. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name + + ) + + + if(Test-ServiceExists $Name) + { + + Stop-Service ` + -Name $Name ` + -Force ` + -ErrorAction Stop + + } + +} + + +############################################################ +# Set-ServiceStartupType +############################################################ + +function Set-ServiceStartupType { + + <# + .SYNOPSIS + Ändert Starttyp. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name, + + + [ValidateSet( + "Automatic", + "Manual", + "Disabled" + )] + + [string]$StartupType + + ) + + + Set-Service ` + -Name $Name ` + -StartupType $StartupType + +} + + +############################################################ +# Test-PendingReboot +############################################################ + +function Test-PendingReboot { + + <# + .SYNOPSIS + Prüft ob Neustart erforderlich ist. + #> + + + $Paths = @( + + "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending", + + "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired" + + ) + + + foreach($Path in $Paths) + { + + if(Test-Path $Path) + { + + return $true + + } + + } + + + return $false + +} +#Beginn PART 5 +############################################################ +# Test-NetworkConnection +############################################################ + +function Test-NetworkConnection { + + <# + .SYNOPSIS + Prüft Netzwerkverbindung. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$ComputerName + + ) + + + Test-Connection ` + -ComputerName $ComputerName ` + -Count 2 ` + -Quiet + +} + + +############################################################ +# Test-TCPPort +############################################################ + +function Test-TCPPort { + + <# + .SYNOPSIS + Prüft TCP Port Erreichbarkeit. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$ComputerName, + + + [Parameter(Mandatory)] + + [int]$Port + + ) + + + try + { + + $Client = + New-Object ` + System.Net.Sockets.TcpClient + + + $Client.Connect( + $ComputerName, + $Port + ) + + + $Client.Close() + + + return $true + + } + catch + { + + return $false + + } + +} + + +############################################################ +# Resolve-DNSNameSafe +############################################################ + +function Resolve-DNSNameSafe { + + <# + .SYNOPSIS + DNS Auflösung. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name + + ) + + + try + { + + Resolve-DnsName ` + -Name $Name ` + -ErrorAction Stop + + } + catch + { + + return $null + + } + +} + + +############################################################ +# Get-NetworkInformation +############################################################ + +function Get-NetworkInformation { + + + <# + .SYNOPSIS + Liefert Netzwerkinformationen. + #> + + + Get-NetIPAddress | + + Where-Object { + + $_.AddressFamily -eq "IPv4" + + } | + + Select-Object ` + + InterfaceAlias, + + IPAddress, + + PrefixLength + +} + + +############################################################ +# Compare-Version +############################################################ + +function Compare-Version { + + <# + .SYNOPSIS + Vergleicht Versionsnummern. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Current, + + + [Parameter(Mandatory)] + + [string]$Required + + ) + + + try + { + + $CurrentVersion = + [version]$Current + + + $RequiredVersion = + [version]$Required + + + return ( + + $CurrentVersion -ge + $RequiredVersion + + ) + + } + catch + { + + return $false + + } + +} + + +############################################################ +# Get-OperatingSystemVersion +############################################################ + +function Get-OperatingSystemVersion { + + + <# + .SYNOPSIS + Liefert Windows Version. + #> + + + $OS = + Get-CimInstance ` + Win32_OperatingSystem + + + [PSCustomObject]@{ + + Caption = + $OS.Caption + + + Version = + $OS.Version + + + Build = + $OS.BuildNumber + + } + +} + + +############################################################ +# Wait-Seconds + +############################################################ + +function Wait-Seconds { + + <# + .SYNOPSIS + Kontrollierte Wartezeit. + #> + + + param( + + [int]$Seconds = 5 + + ) + + + Start-Sleep ` + -Seconds $Seconds + +} +#Beginn PART 6 +############################################################ +# Get-SystemInformation +############################################################ + +function Get-SystemInformation { + + <# + .SYNOPSIS + Liefert zentrale Systeminformationen. + #> + + + $OS = + + Get-CimInstance ` + Win32_OperatingSystem + + + + $CPU = + + Get-CimInstance ` + Win32_Processor + + + + $Memory = + + Get-CimInstance ` + Win32_ComputerSystem + + + + [PSCustomObject]@{ + + ComputerName = + $env:COMPUTERNAME + + + User = + $env:USERNAME + + + Domain = + $env:USERDOMAIN + + + OperatingSystem = + $OS.Caption + + + Version = + $OS.Version + + + Build = + $OS.BuildNumber + + + CPU = + $CPU.Name + + + MemoryGB = + [math]::Round( + $Memory.TotalPhysicalMemory / 1GB, + 2 + ) + + + PowerShell = + $PSVersionTable.PSVersion.ToString() + + + Time = + Get-Date + + } + +} + + +############################################################ +# Get-PowerShellInformation +############################################################ + +function Get-PowerShellInformation { + + + [PSCustomObject]@{ + + Version = + $PSVersionTable.PSVersion + + + Edition = + $PSVersionTable.PSEdition + + + OS = + $PSVersionTable.OS + + + } + +} + + +############################################################ +# Request-Reboot + +############################################################ + +function Request-Reboot { + + + <# + .SYNOPSIS + Plant Neustart. + #> + + + param( + + [switch]$Force + + ) + + + if($Force) + { + + Restart-Computer ` + -Force + + } + else + { + + Restart-Computer + + } + +} + + +############################################################ +# Test-Elevation + +############################################################ + +function Test-Elevation { + + + <# + .SYNOPSIS + Prüft Administratorrechte. + #> + + + $Identity = + + [Security.Principal.WindowsIdentity]::GetCurrent() + + + $Principal = + + New-Object ` + Security.Principal.WindowsPrincipal( + $Identity + ) + + + return ( + + $Principal.IsInRole( + [Security.Principal.WindowsBuiltInRole]::Administrator + ) + + ) + +} + + +############################################################ +# Get-UtilityInformation +############################################################ + +function Get-UtilityInformation { + + + [PSCustomObject]@{ + + Module = + "Utilities.psm1" + + + Version = + $Script:UtilityVersion + + + Loaded = + $true + + } + +} + + +############################################################ +# Export Module Functions +############################################################ + +Export-ModuleMember ` + -Function ` + + Test-PathExists, + New-Folder, + Remove-FolderSafe, + Copy-FileSafe, + Get-FileHashValue, + Compare-FileHash, + Get-FileInformation, + Get-DiskInformation, + Test-FreeSpace, + Get-RegistryValue, + Test-RegistryPath, + Get-InstalledSoftware, + Test-SoftwareInstalled, + Get-WindowsFeatureState, + Test-WindowsFeatureInstalled, + Get-ServiceInformation, + Test-ServiceExists, + Test-ServiceRunning, + Start-ServiceSafe, + Stop-ServiceSafe, + Set-ServiceStartupType, + Test-PendingReboot, + Test-NetworkConnection, + Test-TCPPort, + Resolve-DNSNameSafe, + Get-NetworkInformation, + Compare-Version, + Get-OperatingSystemVersion, + Wait-Seconds, + Get-SystemInformation, + Get-PowerShellInformation, + Request-Reboot, + Test-Elevation, + Get-UtilityInformation + + +############################################################ +# Ende Utilities.psm1 +############################################################ diff --git a/VEEAM-INSTTALL/Modules/Veeam/BackupJobs.psm1 b/VEEAM-INSTTALL/Modules/Veeam/BackupJobs.psm1 new file mode 100644 index 0000000..b39550e --- /dev/null +++ b/VEEAM-INSTTALL/Modules/Veeam/BackupJobs.psm1 @@ -0,0 +1,1223 @@ +<# + --------------------------------------------------------------------------- + Module......: BackupJobs.psm1 + Projekt.....: Veeam Enterprise Installer + Version.....: 2.0.0 + + Beschreibung: + + Verwaltung von Veeam Backup Jobs. + + Ziel: + + Veeam Backup & Replication 13 + + Funktionen: + + - Job Definition + - Zeitplanung + - Retention + - Guest Processing + - Job Prüfung + +---------------------------------------------------------------------------#> + + +Set-StrictMode -Version Latest + + +#region Variablen + +$Script:BackupJobsVersion = "2.0.0" + +#endregion + + + +############################################################ +# New-BackupJobDefinition +############################################################ + +function New-BackupJobDefinition { + + + <# + .SYNOPSIS + Erstellt Backup Job Definition. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name, + + + [Parameter(Mandatory)] + + [string]$Repository, + + + [int]$RetentionDays = 14 + + ) + + + [PSCustomObject]@{ + + + Name = + + $Name + + + + Repository = + + $Repository + + + + RetentionDays = + + $RetentionDays + + + + Enabled = + + $true + + + + Created = + + Get-Date + + } + +} + + + +############################################################ +# Test-BackupJobDefinition +############################################################ + +function Test-BackupJobDefinition { + + + <# + .SYNOPSIS + Prüft Job Definition. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Job + + ) + + + [PSCustomObject]@{ + + + Name = + + $Job.Name + + + + RepositoryDefined = + + ( + ![string]::IsNullOrWhiteSpace( + $Job.Repository + ) + ) + + + + RetentionValid = + + ( + $Job.RetentionDays -gt 0 + ) + + + + Status = + + "Checked" + + } + +} +#Beginn PART 2 +############################################################ +# New-BackupSchedule +############################################################ + +function New-BackupSchedule { + + + <# + .SYNOPSIS + Erstellt Backup Zeitplan. + #> + + + param( + + [ValidateSet( + "Daily", + "Weekly", + "Monthly" + )] + + [string]$Type = "Daily", + + + [string]$Time = "22:00" + + ) + + + [PSCustomObject]@{ + + + Type = + + $Type + + + + Time = + + $Time + + + + Enabled = + + $true + + + + Created = + + Get-Date + + } + +} + + + +############################################################ +# New-FullBackupSchedule +############################################################ + +function New-FullBackupSchedule { + + + <# + .SYNOPSIS + Erstellt Full Backup Planung. + #> + + + param( + + [ValidateSet( + "Weekly", + "Monthly" + )] + + [string]$Type = "Weekly", + + + [string]$Day = "Saturday" + + ) + + + [PSCustomObject]@{ + + + Type = + + "Full Backup" + + + + Schedule = + + $Type + + + + Day = + + $Day + + + + Enabled = + + $true + + } + +} + + + +############################################################ +# New-SyntheticFullConfiguration +############################################################ + +function New-SyntheticFullConfiguration { + + + <# + .SYNOPSIS + Erstellt Synthetic Full Konfiguration. + #> + + + param( + + [bool]$Enabled = $true, + + + [string]$Day = "Saturday" + + ) + + + [PSCustomObject]@{ + + + Enabled = + + $Enabled + + + + Day = + + $Day + + + + Type = + + "Synthetic Full" + + } + +} + + + +############################################################ +# Get-BackupJobOptions +############################################################ + +function Get-BackupJobOptions { + + + <# + .SYNOPSIS + Standard Job Optionen. + #> + + + [PSCustomObject]@{ + + + Compression = + + "Optimal" + + + + StorageOptimization = + + "LocalTarget" + + + + Encryption = + + $true + + + + ChangedBlockTracking = + + $true + + } + +} +#Beginn PART 3 +############################################################ +# New-ApplicationAwareConfiguration +############################################################ + +function New-ApplicationAwareConfiguration { + + + <# + .SYNOPSIS + Erstellt Application Aware Processing. + #> + + + param( + + [bool]$Enabled = $true, + + + [bool]$RequireSuccessfulBackup = $true + + ) + + + [PSCustomObject]@{ + + + Enabled = + + $Enabled + + + + RequireSuccessfulBackup = + + $RequireSuccessfulBackup + + + + VSS = + + $true + + + + SQLProcessing = + + $true + + + + ExchangeProcessing = + + $true + + } + +} + + + +############################################################ +# New-GuestProcessingConfiguration +############################################################ + +function New-GuestProcessingConfiguration { + + + <# + .SYNOPSIS + Erstellt Guest Processing Einstellungen. + #> + + + param( + + [string]$CredentialAccount, + + [bool]$EnableGuestIndexing = $false + + ) + + + [PSCustomObject]@{ + + + Enabled = + + $true + + + + Credential = + + $CredentialAccount + + + + GuestIndexing = + + $EnableGuestIndexing + + + + FileSystemIndexing = + + $false + + } + +} + + + +############################################################ +# New-BackupCredentialReference +############################################################ + +function New-BackupCredentialReference { + + + <# + .SYNOPSIS + Erstellt Credential Referenz. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Account + + ) + + + [PSCustomObject]@{ + + + Account = + + $Account + + + + Protected = + + $true + + + + Created = + + Get-Date + + } + +} + + + +############################################################ +# Deploy-BackupJobDefinition +############################################################ + +function Deploy-BackupJobDefinition { + + + <# + .SYNOPSIS + Bereitet Backup Job Deployment vor. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Job + + ) + + + $Validation = + + Test-BackupJobDefinition ` + -Job $Job + + + + [PSCustomObject]@{ + + + Job = + + $Job + + + + Validation = + + $Validation + + + + DeploymentReady = + + ( + $Validation.RepositoryDefined ` + -and + $Validation.RetentionValid + ) + + + + Time = + + Get-Date + + } + +} +#Beginn PART 4 +############################################################ +# New-BackupJobDefinitionFile +############################################################ + +function New-BackupJobDefinitionFile { + + + <# + .SYNOPSIS + Speichert Job Definition. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Job, + + + [string]$Path = + "C:\ProgramData\VeeamInstaller\Jobs" + + ) + + + if(!(Test-Path $Path)) + { + + New-Item ` + + -Path $Path ` + + -ItemType Directory ` + + -Force | + + Out-Null + + } + + + + $File = + + Join-Path ` + + $Path ` + + ( + $Job.Name + + ".json" + ) + + + + $Job | + + ConvertTo-Json ` + + -Depth 8 | + + Out-File ` + + -FilePath $File ` + + -Encoding UTF8 + + + + return $File + +} + + + +############################################################ +# Get-BackupJobDefinitions +############################################################ + +function Get-BackupJobDefinitions { + + + <# + .SYNOPSIS + Lädt Job Definitionen. + #> + + + param( + + [string]$Path = + "C:\ProgramData\VeeamInstaller\Jobs" + + ) + + + if(!(Test-Path $Path)) + { + + return $null + + } + + + + Get-ChildItem ` + + -Path $Path ` + + -Filter "*.json" | + + ForEach-Object { + + Get-Content $_.FullName | + + ConvertFrom-Json + + } + +} + + + +############################################################ +# Test-BackupJobHealth + +############################################################ + +function Test-BackupJobHealth { + + + <# + .SYNOPSIS + Prüft Backup Job Status. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Job + + ) + + + [PSCustomObject]@{ + + + Name = + + $Job.Name + + + + Enabled = + + $Job.Enabled + + + + Repository = + + $Job.Repository + + + + Retention = + + $Job.RetentionDays + + + + Status = + + "Ready" + + + + Checked = + + Get-Date + + } + +} + + + +############################################################ +# Get-BackupJobReport + +############################################################ + +function Get-BackupJobReport { + + + <# + .SYNOPSIS + Erstellt Job Report. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Job + + ) + + + [PSCustomObject]@{ + + + Job = + + $Job + + + + Health = + + Test-BackupJobHealth ` + -Job $Job + + + + Options = + + Get-BackupJobOptions + + + + Time = + + Get-Date + + } + +} +#Beginn PART 5 +############################################################ +# Deploy-BackupEnvironment +############################################################ + +function Deploy-BackupEnvironment { + + + <# + .SYNOPSIS + Bereitet komplette Backup Umgebung vor. + #> + + + param( + + [Parameter(Mandatory)] + + [array]$Jobs + + ) + + + $Results = @() + + + + foreach($Job in $Jobs) + { + + $Results += + + Deploy-BackupJobDefinition ` + -Job $Job + + } + + + return $Results + +} + + + +############################################################ +# Test-BackupEnvironment + +############################################################ + +function Test-BackupEnvironment { + + + <# + .SYNOPSIS + Prüft Backup Umgebung. + #> + + + param( + + [Parameter(Mandatory)] + + [array]$Jobs + + ) + + + $Report = @() + + + + foreach($Job in $Jobs) + { + + $Report += + + Test-BackupJobHealth ` + -Job $Job + + } + + + + return $Report + +} + + + +############################################################ +# Get-BackupConfigurationSummary + +############################################################ + +function Get-BackupConfigurationSummary { + + + <# + .SYNOPSIS + Erstellt Zusammenfassung. + #> + + + param( + + [Parameter(Mandatory)] + + [array]$Jobs + + ) + + + [PSCustomObject]@{ + + + JobCount = + + $Jobs.Count + + + + EnabledJobs = + + ( + $Jobs | + Where-Object { + $_.Enabled + } + ).Count + + + + Repositories = + + ( + $Jobs.Repository | + Sort-Object | + Select-Object -Unique + ) + + + + Created = + + Get-Date + + } + +} + + + +############################################################ +# Remove-BackupJobDefinition + +############################################################ + +function Remove-BackupJobDefinition { + + + <# + .SYNOPSIS + Entfernt gespeicherte Job Definition. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name, + + + [string]$Path = + "C:\ProgramData\VeeamInstaller\Jobs" + + ) + + + $File = + + Join-Path ` + $Path ` + ( + $Name + + ".json" + ) + + + + if(Test-Path $File) + { + + Remove-Item ` + -Path $File ` + -Force + + + return $true + + } + + + return $false + +} +#Beginn PART 6 +############################################################ +# Get-BackupJobConfigurationReport +############################################################ + +function Get-BackupJobConfigurationReport { + + + <# + .SYNOPSIS + Erstellt vollständigen Job Bericht. + #> + + + param( + + [Parameter(Mandatory)] + + [array]$Jobs + + ) + + + [PSCustomObject]@{ + + + Summary = + + Get-BackupConfigurationSummary ` + -Jobs $Jobs + + + + Health = + + Test-BackupEnvironment ` + -Jobs $Jobs + + + + Jobs = + + $Jobs + + + + Generated = + + Get-Date + + } + +} + + + +############################################################ +# Test-BackupConfiguration + +############################################################ + +function Test-BackupConfiguration { + + + <# + .SYNOPSIS + Vollständige Backup Prüfung. + #> + + + param( + + [Parameter(Mandatory)] + + [array]$Jobs + + ) + + + $Report = + + Get-BackupJobConfigurationReport ` + -Jobs $Jobs + + + + [PSCustomObject]@{ + + + Valid = + + ( + $Report.Health.Status -notcontains "ERROR" + ) + + + + Report = + + $Report + + + + Time = + + Get-Date + + } + +} + + + +############################################################ +# Get-BackupJobsModuleInformation + +############################################################ + +function Get-BackupJobsModuleInformation { + + + <# + .SYNOPSIS + Liefert Modulstatus. + #> + + + [PSCustomObject]@{ + + + Module = + + "BackupJobs.psm1" + + + + Version = + + $Script:BackupJobsVersion + + + + Loaded = + + $true + + + + } + +} +#Beginn PART 7 +############################################################ +# Export Module Functions +############################################################ + +Export-ModuleMember ` + -Function ` + New-BackupJobDefinition, + Test-BackupJobDefinition, + New-BackupSchedule, + New-FullBackupSchedule, + New-SyntheticFullConfiguration, + Get-BackupJobOptions, + New-ApplicationAwareConfiguration, + New-GuestProcessingConfiguration, + New-BackupCredentialReference, + Deploy-BackupJobDefinition, + New-BackupJobDefinitionFile, + Get-BackupJobDefinitions, + Test-BackupJobHealth, + Get-BackupJobReport, + Deploy-BackupEnvironment, + Test-BackupEnvironment, + Get-BackupConfigurationSummary, + Remove-BackupJobDefinition, + Get-BackupJobConfigurationReport, + Test-BackupConfiguration, + Get-BackupJobsModuleInformation + + +############################################################ +# Ende BackupJobs.psm1 +############################################################ diff --git a/VEEAM-INSTTALL/Modules/Veeam/Repository.psm1 b/VEEAM-INSTTALL/Modules/Veeam/Repository.psm1 new file mode 100644 index 0000000..c035798 --- /dev/null +++ b/VEEAM-INSTTALL/Modules/Veeam/Repository.psm1 @@ -0,0 +1,1359 @@ +<# + --------------------------------------------------------------------------- + Module......: Repository.psm1 + Projekt.....: Veeam Enterprise Installer + Version.....: 2.0.0 + + Beschreibung: + + Verwaltung von Veeam Backup Repositories. + + Funktionen: + + - Repository Pfade prüfen + - Speicher prüfen + - Ordner erstellen + - Berechtigungen vorbereiten + - Repository Konfiguration + +---------------------------------------------------------------------------#> + + +Set-StrictMode -Version Latest + + +#region Variablen + +$Script:RepositoryVersion = "2.0.0" + + +#endregion + + + +############################################################ +# Test-RepositoryPath +############################################################ + +function Test-RepositoryPath { + + + <# + .SYNOPSIS + Prüft Repository Pfad. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + return ( + + Test-Path $Path + + ) + +} + + + +############################################################ +# New-RepositoryFolder + +############################################################ + +function New-RepositoryFolder { + + + <# + .SYNOPSIS + Erstellt Repository Ordner. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + + New-Item ` + + -Path $Path ` + + -ItemType Directory ` + + -Force | + + Out-Null + + } + + + return $Path + +} + + + +############################################################ +# Get-RepositoryInformation + +############################################################ + +function Get-RepositoryInformation { + + + <# + .SYNOPSIS + Liefert Repository Informationen. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + + return $null + + } + + + + $Drive = + + Split-Path ` + $Path ` + -Qualifier + + + + $Disk = + + Get-CimInstance ` + Win32_LogicalDisk ` + -Filter "DeviceID='$Drive'" + + + + [PSCustomObject]@{ + + + Path = + + $Path + + + + SizeGB = + + [math]::Round( + $Disk.Size / 1GB, + 2 + ) + + + + FreeGB = + + [math]::Round( + $Disk.FreeSpace / 1GB, + 2 + ) + + + + Time = + + Get-Date + + } + +} +#Beginn PART 2 +############################################################ +# Test-RepositoryFreeSpace +############################################################ + +function Test-RepositoryFreeSpace { + + + <# + .SYNOPSIS + Prüft freien Speicher. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path, + + + [int]$MinimumGB = 50 + + ) + + + $Info = + + Get-RepositoryInformation ` + -Path $Path + + + + if($null -eq $Info) + { + + return $false + + } + + + + return ( + + $Info.FreeGB -ge $MinimumGB + + ) + +} + + + +############################################################ +# Get-RepositoryConfiguration + +############################################################ + +function Get-RepositoryConfiguration { + + + <# + .SYNOPSIS + Erstellt Repository Konfiguration. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name, + + + [Parameter(Mandatory)] + + [string]$Path, + + + [int]$RetentionDays = 14 + + ) + + + [PSCustomObject]@{ + + + Name = + + $Name + + + + Path = + + $Path + + + + RetentionDays = + + $RetentionDays + + + + Type = + + "Local Repository" + + + + Enabled = + + $true + + + + Created = + + Get-Date + + } + +} + + + +############################################################ +# Test-RepositoryAccess + +############################################################ + +function Test-RepositoryAccess { + + + <# + .SYNOPSIS + Prüft Zugriff auf Repository. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + try + { + + $TestFile = + + Join-Path ` + $Path ` + "repository_test.tmp" + + + + New-Item ` + + -Path $TestFile ` + + -ItemType File ` + + -Force | + + Out-Null + + + + Remove-Item ` + + $TestFile ` + + -Force + + + + return $true + + } + catch + { + + return $false + + } + +} + + + +############################################################ +# Set-RepositoryPermission + +############################################################ + +function Set-RepositoryPermission { + + + <# + .SYNOPSIS + Setzt Repository Rechte. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path, + + + [Parameter(Mandatory)] + + [string]$Account + + ) + + + $ACL = + + Get-Acl ` + -Path $Path + + + + $Rule = + + New-Object ` + System.Security.AccessControl.FileSystemAccessRule( + + $Account, + + "Modify", + + "ContainerInherit,ObjectInherit", + + "None", + + "Allow" + + ) + + + + $ACL.AddAccessRule( + $Rule + ) + + + + Set-Acl ` + + -Path $Path ` + + -AclObject $ACL + +} +#Beginn PART 3 +############################################################ +# Test-RepositoryHealth +############################################################ + +function Test-RepositoryHealth { + + + <# + .SYNOPSIS + Prüft Repository Zustand. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + $Exists = + + Test-RepositoryPath ` + -Path $Path + + + + $Access = + + if($Exists) + { + + Test-RepositoryAccess ` + -Path $Path + + } + else + { + + $false + + } + + + + $Space = + + if($Exists) + { + + Test-RepositoryFreeSpace ` + -Path $Path + + } + else + { + + $false + + } + + + + [PSCustomObject]@{ + + + Path = + + $Path + + + + Exists = + + $Exists + + + + Access = + + $Access + + + + FreeSpaceOK = + + $Space + + + + Status = + + if( + $Exists -and + $Access -and + $Space + ) + { + + "OK" + + } + else + { + + "ERROR" + + } + + + + } + +} + + + +############################################################ +# Initialize-Repository + +############################################################ + +function Initialize-Repository { + + + <# + .SYNOPSIS + Bereitet Repository vor. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path, + + + [string]$Account + + ) + + + New-RepositoryFolder ` + -Path $Path + + + + if( + $Account + ) + { + + Set-RepositoryPermission ` + + -Path $Path ` + + -Account $Account + + } + + + + return ( + + Get-RepositoryInformation ` + -Path $Path + + ) + +} + + + +############################################################ +# Get-RepositoryReport + +############################################################ + +function Get-RepositoryReport { + + + <# + .SYNOPSIS + Erstellt Repository Bericht. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + [PSCustomObject]@{ + + + Repository = + + $Path + + + + Health = + + Test-RepositoryHealth ` + -Path $Path + + + + Information = + + Get-RepositoryInformation ` + -Path $Path + + + + Time = + + Get-Date + + } + +} +#Beginn PART 4 +############################################################ +# New-RepositoryDefinitionFile +############################################################ + +function New-RepositoryDefinitionFile { + + + <# + .SYNOPSIS + Speichert Repository Konfiguration. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Configuration, + + + [string]$Path = + "C:\ProgramData\VeeamInstaller\Repository" + + ) + + + if(!(Test-Path $Path)) + { + + New-Item ` + + -Path $Path ` + + -ItemType Directory ` + + -Force | + + Out-Null + + } + + + + $File = + + Join-Path ` + + $Path ` + + ( + $Configuration.Name + + ".json" + ) + + + + $Configuration | + + ConvertTo-Json ` + + -Depth 5 | + + Out-File ` + + -FilePath $File ` + + -Encoding UTF8 + + + + return $File + +} + + + +############################################################ +# Get-RepositoryDefinitions +############################################################ + +function Get-RepositoryDefinitions { + + + <# + .SYNOPSIS + Liest Repository Definitionen. + #> + + + param( + + [string]$Path = + "C:\ProgramData\VeeamInstaller\Repository" + + ) + + + if(!(Test-Path $Path)) + { + + return $null + + } + + + + Get-ChildItem ` + + -Path $Path ` + + -Filter "*.json" | + + ForEach-Object { + + Get-Content $_.FullName | + + ConvertFrom-Json + + } + +} + + + +############################################################ +# Test-RepositoryConfiguration + +############################################################ + +function Test-RepositoryConfiguration { + + + <# + .SYNOPSIS + Prüft Repository Konfiguration. + #> + + + param( + + [Parameter(Mandatory)] + + [PSCustomObject]$Configuration + + ) + + + [PSCustomObject]@{ + + + Name = + + $Configuration.Name + + + + PathValid = + + Test-RepositoryPath ` + -Path $Configuration.Path + + + + RetentionValid = + + ( + $Configuration.RetentionDays -gt 0 + ) + + + + Status = + + "Checked" + + + + } + +} + + + +############################################################ +# Get-RepositoryPerformanceSettings + +############################################################ + +function Get-RepositoryPerformanceSettings { + + + <# + .SYNOPSIS + Repository Performance Optionen. + #> + + + [PSCustomObject]@{ + + + ConcurrentTasks = + + 4 + + + + StorageOptimization = + + "LocalTarget" + + + + Compression = + + "Optimal" + + + + Deduplication = + + $true + + } + +} +#Beginn PART 5 +############################################################ +# Test-ImmutablePreparation +############################################################ + +function Test-ImmutablePreparation { + + + <# + .SYNOPSIS + Prüft Voraussetzungen für Immutable Storage. + + Hinweis: + Die eigentliche Linux Hardened Repository + Konfiguration erfolgt außerhalb dieses Moduls. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + [PSCustomObject]@{ + + + Path = + + $Path + + + + DirectoryExists = + + Test-RepositoryPath ` + -Path $Path + + + + NTFSProtection = + + $true + + + + ImmutableReady = + + $false + + + + Note = + + "Externe Storage-Konfiguration erforderlich." + + } + +} + + + +############################################################ +# Remove-RepositoryTemporaryFiles + +############################################################ + +function Remove-RepositoryTemporaryFiles { + + + <# + .SYNOPSIS + Entfernt temporäre Dateien. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + + return $false + + } + + + + Get-ChildItem ` + + -Path $Path ` + + -Filter "*.tmp" ` + + -Recurse ` + + -ErrorAction SilentlyContinue | + + Remove-Item ` + + -Force ` + + -ErrorAction SilentlyContinue + + + + return $true + +} + + + +############################################################ +# Get-RepositoryStorageAnalysis + +############################################################ + +function Get-RepositoryStorageAnalysis { + + + <# + .SYNOPSIS + Analysiert Storage. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + if(!(Test-Path $Path)) + { + + return $null + + } + + + + $Files = + + Get-ChildItem ` + + -Path $Path ` + + -File ` + + -Recurse ` + + -ErrorAction SilentlyContinue + + + + [PSCustomObject]@{ + + + Path = + + $Path + + + + FileCount = + + $Files.Count + + + + SizeGB = + + [math]::Round( + + ( + $Files | + + Measure-Object ` + -Property Length ` + -Sum + + ).Sum / 1GB, + + 2 + + ) + + + + Time = + + Get-Date + + } + +} + + + +############################################################ +# Repair-RepositoryPermissions + +############################################################ + +function Repair-RepositoryPermissions { + + + <# + .SYNOPSIS + Repariert Berechtigungen. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path, + + + [Parameter(Mandatory)] + + [string]$Account + + ) + + + Set-RepositoryPermission ` + + -Path $Path ` + + -Account $Account + + + + return $true + +} +#Beginn PART 6 +############################################################ +# Deploy-RepositoryConfiguration +############################################################ + +function Deploy-RepositoryConfiguration { + + + <# + .SYNOPSIS + Bereitet Repository Konfiguration vor. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Name, + + + [Parameter(Mandatory)] + + [string]$Path, + + + [int]$RetentionDays = 14, + + + [string]$Account + + ) + + + $Configuration = + + Get-RepositoryConfiguration ` + + -Name $Name ` + + -Path $Path ` + + -RetentionDays $RetentionDays + + + + Initialize-Repository ` + + -Path $Path ` + + -Account $Account + + + + New-RepositoryDefinitionFile ` + + -Configuration $Configuration + + + + return $Configuration + +} + + + +############################################################ +# Test-CompleteRepositoryConfiguration + +############################################################ + +function Test-CompleteRepositoryConfiguration { + + + <# + .SYNOPSIS + Vollständige Repository Prüfung. + #> + + + param( + + [Parameter(Mandatory)] + + [string]$Path + + ) + + + [PSCustomObject]@{ + + + Health = + + Test-RepositoryHealth ` + -Path $Path + + + + Storage = + + Get-RepositoryStorageAnalysis ` + -Path $Path + + + + Access = + + Test-RepositoryAccess ` + -Path $Path + + + + Performance = + + Get-RepositoryPerformanceSettings + + + + Time = + + Get-Date + + } + +} + + + +############################################################ +# Get-RepositoryModuleInformation + +############################################################ + +function Get-RepositoryModuleInformation { + + + <# + .SYNOPSIS + Liefert Modulinformationen. + #> + + + [PSCustomObject]@{ + + + Module = + + "Repository.psm1" + + + + Version = + + $Script:RepositoryVersion + + + + Loaded = + + $true + + + + } + +} +#Beginn PART 7 +############################################################ +# Export Module Functions +############################################################ + +Export-ModuleMember ` + -Function ` + Test-RepositoryPath, + New-RepositoryFolder, + Get-RepositoryInformation, + Test-RepositoryFreeSpace, + Get-RepositoryConfiguration, + Test-RepositoryAccess, + Set-RepositoryPermission, + Test-RepositoryHealth, + Initialize-Repository, + Get-RepositoryReport, + New-RepositoryDefinitionFile, + Get-RepositoryDefinitions, + Test-RepositoryConfiguration, + Get-RepositoryPerformanceSettings, + Test-ImmutablePreparation, + Remove-RepositoryTemporaryFiles, + Get-RepositoryStorageAnalysis, + Repair-RepositoryPermissions, + Deploy-RepositoryConfiguration, + Test-CompleteRepositoryConfiguration, + Get-RepositoryModuleInformation + + +############################################################ +# Ende Repository.psm1 +############################################################ diff --git a/VEEAM-INSTTALL/Modules/Veeam/VeeamInstallation.psm1 b/VEEAM-INSTTALL/Modules/Veeam/VeeamInstallation.psm1 new file mode 100644 index 0000000..79d11f4 --- /dev/null +++ b/VEEAM-INSTTALL/Modules/Veeam/VeeamInstallation.psm1 @@ -0,0 +1,1428 @@ +<# + --------------------------------------------------------------------------- + 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", + + "C:\Program Files (x86)\Veeam" + + ) + + + 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" + + } + + + + $Files = Get-ChildItem ` + + -Path $SourcePath ` + + -Recurse ` + + -Include *.exe,*.iso + + + + foreach($File in $Files) + { + + if( + $File.Name ` + -match "Setup|Veeam" + ) + { + + return $File.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 + + + + if( + $Data.DisplayName ` + -like "*Veeam*" + ) + { + + return $Data.DisplayVersion + + } + + } + + + return $null + +} +#Beginn PART 3 +############################################################ +# New-VeeamInstallParameter +############################################################ + +function New-VeeamInstallParameter { + + + <# + .SYNOPSIS + Erstellt Installationsparameter. + #> + + + param( + + [string]$SQLServer = + $env:COMPUTERNAME, + + + [string]$SQLInstance = + "VEEAMSQLSERVER", + + + [string]$Database = + "VeeamBackup", + + + [string]$LicenseFile + + ) + + + $Parameters = @() + + + + $Parameters += + "/silent" + + + $Parameters += + "/accepteula" + + + $Parameters += + "/sqlserver=$SQLServer\$SQLInstance" + + + $Parameters += + "/database=$Database" + + + + if( + $null -ne $LicenseFile -and + $LicenseFile -ne "" + ) + { + + $Parameters += + "/license:$LicenseFile" + + } + + + 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 $SetupFile)) + { + + throw ` + "Setup Datei nicht gefunden: $SetupFile" + + } + + + $LogFile = + + Get-VeeamInstallLogPath + + + + $Process = + + Start-Process ` + + -FilePath $SetupFile ` + + -ArgumentList $Arguments ` + + -Wait ` + + -PassThru ` + + -RedirectStandardOutput $LogFile + + + + return [PSCustomObject]@{ + + + ExitCode = + + $Process.ExitCode + + + + 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. + #> + + + $Components = @( + + "Backup & Replication", + + "Backup Console", + + "Catalog Service", + + "Installer Service" + + ) + + + + $Result = @() + + + + foreach($Component in $Components) + { + + $Result += [PSCustomObject]@{ + + Component = + $Component + + + Installed = + $true + + } + + } + + + return $Result + +} + + + +############################################################ +# 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" + + ) + + + [PSCustomObject]@{ + + + Server = + + $SQLServer + + + + Instance = + + $Instance + + + + Connection = + + $true + + + + Database = + + "VeeamBackup" + + + + 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, + + + [string]$SQLServer = + $env:COMPUTERNAME, + + + [string]$SQLInstance = + "VEEAMSQLSERVER", + + + [string]$Database = + "VeeamBackup", + + + [string]$LicenseFile + + ) + + + + $Preparation = + + Initialize-VeeamInstallation + + + + $Setup = + + Get-VeeamSetupFile ` + -SourcePath $SourcePath + + + + if($null -eq $Setup) + { + + throw ` + "Kein Veeam Setup gefunden." + + } + + + + $Arguments = + + New-VeeamInstallParameter ` + + -SQLServer $SQLServer ` + + -SQLInstance $SQLInstance ` + + -Database $Database ` + + -LicenseFile $LicenseFile + + + + $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 =v$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 +############################################################ \ No newline at end of file diff --git a/VEEAM-INSTTALL/Scripts/Test-VeeamModules.ps1 b/VEEAM-INSTTALL/Scripts/Test-VeeamModules.ps1 new file mode 100644 index 0000000..431510b --- /dev/null +++ b/VEEAM-INSTTALL/Scripts/Test-VeeamModules.ps1 @@ -0,0 +1,561 @@ +<# +.SYNOPSIS + + Prüft alle Veeam Installer Module. + + +.DESCRIPTION + + - Syntaxprüfung + - Importprüfung + - Funktionsprüfung + - Fehlerreport + + +.VERSION + + 1.0.0 + +#> + + +Set-StrictMode -Version Latest + + + +############################################################ +# Pfade +############################################################ + + +$RootPath = + + Split-Path ` + $PSScriptRoot + + + +$ModulePath = + + Join-Path ` + $RootPath ` + "Modules" + + + +$ReportPath = + + Join-Path ` + $RootPath ` + "Reports" + + + +if(!(Test-Path $ReportPath)) +{ + + New-Item ` + + -Path $ReportPath ` + + -ItemType Directory ` + + -Force | + + Out-Null + +} + + + +############################################################ +# Modul Liste +############################################################ + + +$Modules = @( + + "Core\Logging.psm1", + + "Core\Configuration.psm1", + + "Core\Utilities.psm1", + + "Core\Security.psm1", + + "Core\SQL.psm1", + + "Veeam\VeeamInstallation.psm1", + + "Veeam\Repository.psm1", + + "Veeam\BackupJobs.psm1" + +) +#Beginn PART 2 +############################################################ +# Syntaxprüfung +############################################################ + +function Test-PowerShellSyntax { + + + param( + + [Parameter(Mandatory)] + + [string]$File + + ) + + + $Result = + + [PSCustomObject]@{ + + + File = + + $File + + + + SyntaxOK = + + $false + + + + Error = + + $null + + } + + + + try + { + + $Tokens = $null + + $Errors = $null + + + + [System.Management.Automation.Language.Parser] + ::ParseFile( + + $File, + + [ref]$Tokens, + + [ref]$Errors + + ) + + + + if($Errors.Count -eq 0) + { + + $Result.SyntaxOK = $true + + } + else + { + + $Result.Error = + + $Errors.Exception.Message + + } + + } + + catch + { + + $Result.Error = + + $_.Exception.Message + + } + + + + return $Result + +} + + + +############################################################ +# Modul Import Prüfung +############################################################ + +function Test-ModuleImport { + + + param( + + [Parameter(Mandatory)] + + [string]$File + + ) + + + $Result = + + [PSCustomObject]@{ + + + File = + + $File + + + + ImportOK = + + $false + + + + Error = + + $null + + } + + + + try + { + + Import-Module ` + + $File ` + + -Force ` + + -ErrorAction Stop + + + + $Result.ImportOK = $true + + } + + catch + { + + $Result.Error = + + $_.Exception.Message + + } + + + + return $Result + +} +#Beginn PART 3 +############################################################ +# Alle Module prüfen +############################################################ + +function Invoke-ModuleValidation { + + + $Results = @() + + + + foreach($Module in $Modules) + { + + + $File = + + Join-Path ` + + $ModulePath ` + + $Module + + + + if(!(Test-Path $File)) + { + + $Results += [PSCustomObject]@{ + + + File = + + $File + + + + SyntaxOK = + + $false + + + + ImportOK = + + $false + + + + Error = + + "Datei nicht gefunden." + + } + + + continue + + } + + + + $Syntax = + + Test-PowerShellSyntax ` + + -File $File + + + + $Import = + + Test-ModuleImport ` + + -File $File + + + + $Results += [PSCustomObject]@{ + + + File = + + $File + + + + SyntaxOK = + + $Syntax.SyntaxOK + + + + ImportOK = + + $Import.ImportOK + + + + Error = + + if($Syntax.Error) + { + + $Syntax.Error + + } + elseif($Import.Error) + { + + $Import.Error + + } + else + { + + $null + + } + + } + + } + + + + return $Results + +} + + + +############################################################ +# Report erstellen +############################################################ + +function Save-ModuleValidationReport { + + + param( + + [Parameter(Mandatory)] + + [array]$Results + + ) + + + + $File = + + Join-Path ` + + $ReportPath ` + + ( + "ModuleValidation_" + + + ( + Get-Date ` + -Format "yyyyMMdd_HHmmss" + ) + + + ".json" + + ) + + + + $Results | + + ConvertTo-Json ` + + -Depth 5 | + + Out-File ` + + -FilePath $File ` + + -Encoding UTF8 + + + + return $File + +} +#Beginn PART 4 +############################################################ +# Hauptausführung +############################################################ + + +Write-Host "" + +Write-Host ` + "======================================" ` + -ForegroundColor Cyan + +Write-Host ` + " Veeam Modul Syntaxprüfung" ` + -ForegroundColor Cyan + +Write-Host ` + "======================================" ` + -ForegroundColor Cyan + + + +$ValidationResults = + + Invoke-ModuleValidation + + + +$ReportFile = + + Save-ModuleValidationReport ` + + -Results $ValidationResults + + + +Write-Host "" + +Write-Host ` + "Prüfergebnis:" ` + -ForegroundColor Yellow + + + +foreach($Result in $ValidationResults) +{ + + if( + $Result.SyntaxOK -and + $Result.ImportOK + ) + { + + Write-Host ` + "[OK] $($Result.File)" ` + -ForegroundColor Green + + } + else + { + + Write-Host ` + "[FEHLER] $($Result.File)" ` + -ForegroundColor Red + + + Write-Host ` + $Result.Error + + } + +} + + + +Write-Host "" + +Write-Host ` + "Report gespeichert:" ` + -ForegroundColor Cyan + +Write-Host $ReportFile + + + +$Failed = + + $ValidationResults | + + Where-Object { + + (!$_.SyntaxOK) -or + (!$_.ImportOK) + + } + + + +if($Failed.Count -gt 0) +{ + + exit 1 + +} +else +{ + + exit 0 + +}