Files

471 lines
8.5 KiB
PowerShell
Executable File
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
############################################################
# PART 4.1
#
# PART 4.1 Betriebssystem prüfen
############################################################
function Test-OperatingSystem {
Write-Log "Prüfe Betriebssystem"
try {
$OS = Get-CimInstance Win32_OperatingSystem
}
catch {
Stop-Installation "Betriebssystem konnte nicht ermittelt werden."
}
Write-Log "Betriebssystem : $($OS.Caption)"
Write-Log "Version : $($OS.Version)"
Write-Log "Build : $($OS.BuildNumber)"
if($OS.ProductType -ne 3)
{
Stop-Installation "Dieses Script unterstützt nur Windows Server."
}
switch -Regex ($OS.Caption)
{
"2022"
{
Write-Log "Windows Server 2022 erkannt."
}
"2025"
{
Write-Log "Windows Server 2025 erkannt."
}
default
{
Stop-Installation "Nicht unterstütztes Betriebssystem."
}
}
}
############################################################
# PART 4.2
#
# PART 4.2 PowerShell-Version prüfen
############################################################
function Test-PowerShellVersion {
Write-Log "Prüfe PowerShell"
$PSVersion = $PSVersionTable.PSVersion
Write-Log "PowerShell Version: $PSVersion"
if($PSVersion.Major -lt 5)
{
Stop-Installation "PowerShell 5.1 oder höher wird benötigt."
}
if($PSVersion.Major -ge 7)
{
Write-Log "PowerShell 7 erkannt."
}
else
{
Write-Log "PowerShell 5.x erkannt."
}
}
############################################################
# PART 4.3
#
# PART 4.3 CPU prüfen
############################################################
function Test-CPU {
Write-Log "Prüfe CPU"
$CPU = Get-CimInstance Win32_Processor
Write-Log "CPU : $($CPU.Name)"
Write-Log "Kerne : $($CPU.NumberOfCores)"
Write-Log "Logische CPUs : $($CPU.NumberOfLogicalProcessors)"
if($CPU.NumberOfLogicalProcessors -lt 2)
{
Stop-Installation "Mindestens 2 logische Prozessoren erforderlich."
}
}
############################################################
# PART 4.4
#
# PART 4.4 RAM prüfen
############################################################
function Test-Memory {
Write-Log "Prüfe Arbeitsspeicher"
$RAM = (Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory
$RAMGB = [Math]::Round($RAM / 1GB,2)
Write-Log "RAM : $RAMGB GB"
if($RAMGB -lt 8)
{
Stop-Installation "Mindestens 8 GB RAM erforderlich."
}
}
############################################################
# PART 4.5
#
# PART 4.5 Laufwerke prüfen
############################################################
function Test-Drive {
param(
[Parameter(Mandatory)]
[string]$DriveLetter,
[Parameter(Mandatory)]
[int]$MinimumFreeGB
)
Write-Log "Prüfe Laufwerk $DriveLetter"
$Drive = Get-CimInstance Win32_LogicalDisk |
Where-Object DeviceID -eq $DriveLetter
if(!$Drive)
{
Stop-Installation "Laufwerk $DriveLetter existiert nicht."
}
$Free = [Math]::Round($Drive.FreeSpace / 1GB,2)
Write-Log "Freier Speicher : $Free GB"
if($Free -lt $MinimumFreeGB)
{
Stop-Installation "Zu wenig Speicher auf $DriveLetter."
}
}
############################################################
# PART 4.6
#
# PART 4.6 Installationspfade prüfen
############################################################
function Test-InstallationPaths {
Write-Log "Prüfe Installationslaufwerke"
Test-Drive "C:" 10
Test-Drive "F:" 20
Test-Drive "H:" 20
}
############################################################
# PART 4.7
#
# PART 4.7 Pending Reboot
############################################################
function Test-PendingReboot {
Write-Log "Prüfe Pending Reboot"
$Pending = $false
if(Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Component Based Servicing\RebootPending")
{
$Pending = $true
}
if(Test-Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\RebootRequired")
{
$Pending = $true
}
if(Get-ItemProperty `
"HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager" `
-ErrorAction SilentlyContinue |
Select-Object -ExpandProperty PendingFileRenameOperations `
-ErrorAction SilentlyContinue)
{
$Pending = $true
}
if($Pending)
{
Write-Log "Pending Reboot erkannt."
Restart-AndResume
}
Write-Log "Kein Pending Reboot."
}
############################################################
# PART 4.8
#
# PART 4.8 Gesamter Systemcheck
############################################################
function Invoke-SystemCheck {
Write-Log ""
Write-Log "===================================="
Write-Log "Systemprüfung gestartet"
Write-Log "===================================="
Test-OperatingSystem
Test-PowerShellVersion
Test-CPU
Test-Memory
Test-InstallationPaths
Test-PendingReboot
Write-Log "Systemprüfung erfolgreich abgeschlossen."
}
############################################################
# PART 4.9
#
# SQL Server Prüfung
#
# SQL Server 2022 Standard
# Instanz VEEAMSQLSERVER
############################################################
function Test-SQLInstance {
Write-Log "===================================="
Write-Log "Prüfe SQL Instanz"
Write-Log "===================================="
#
# Variablen
#
$SQLInstanceName = "VEEAMSQLSERVER"
$SQLServerName = $env:COMPUTERNAME
$SQLConnection = "$SQLServerName\$SQLInstanceName"
Write-Log "SQL Server : $SQLConnection"
#
# SQL Dienst prüfen
#
$ServiceName = "MSSQL`$$SQLInstanceName"
$SQLService = Get-Service `
-Name $ServiceName `
-ErrorAction SilentlyContinue
if(!$SQLService)
{
Stop-Installation `
"SQL Instanz $SQLInstanceName wurde nicht gefunden."
}
Write-Log "SQL Dienst gefunden"
Write-Log "Status: $($SQLService.Status)"
if($SQLService.Status -ne "Running")
{
Stop-Installation `
"SQL Dienst läuft nicht."
}
#
# SQL Verbindung testen
#
Write-Log "Teste SQL Verbindung"
try
{
Add-Type -AssemblyName System.Data
$ConnectionString = @"
Server=$SQLConnection;
Integrated Security=True;
Database=master;
Connection Timeout=10;
"@
$Connection = New-Object `
System.Data.SqlClient.SqlConnection
$Connection.ConnectionString =
$ConnectionString
$Connection.Open()
Write-Log "SQL Verbindung erfolgreich"
#
# SQL Version lesen
#
$Command = $Connection.CreateCommand()
$Command.CommandText =
"SELECT SERVERPROPERTY('ProductVersion'),
SERVERPROPERTY('Edition'),
SERVERPROPERTY('ProductLevel')"
$Reader = $Command.ExecuteReader()
while($Reader.Read())
{
$SQLVersion = $Reader.GetValue(0)
$SQLEdition = $Reader.GetValue(1)
$SQLLevel = $Reader.GetValue(2)
Write-Log "SQL Version : $SQLVersion"
Write-Log "Edition : $SQLEdition"
Write-Log "Level : $SQLLevel"
}
$Reader.Close()
#
# Datenbank prüfen
#
$Command = $Connection.CreateCommand()
$Command.CommandText =
@"
SELECT name
FROM sys.databases
WHERE name='VeeamBackup'
"@
$Result = $Command.ExecuteScalar()
if($Result)
{
Write-Log "VeeamBackup Datenbank vorhanden"
}
else
{
Write-Log "VeeamBackup Datenbank wird durch Veeam Setup erstellt"
}
#
# Login Rechte prüfen
#
$Command.CommandText =
@"
SELECT IS_SRVROLEMEMBER('sysadmin')
"@
$SysAdmin =
$Command.ExecuteScalar()
if($SysAdmin -eq 1)
{
Write-Log "Installationskonto besitzt SQL Sysadmin Rechte"
}
else
{
Write-Log "WARNUNG: Konto besitzt keine SQL Sysadmin Rolle"
}
$Connection.Close()
}
catch
{
Stop-Installation `
"SQL Verbindung fehlgeschlagen:`n$($_.Exception.Message)"
}
Write-Log "SQL Prüfung erfolgreich"
}