Initialer Import der Synology Scripts
This commit is contained in:
Executable
+54
@@ -0,0 +1,54 @@
|
||||
# Konfigurierbare Variablen
|
||||
$VMName = "DeploymentClient" # Name der VM
|
||||
$VMPath = "C:\HyperV\VMs\$VMName" # Speicherort der VM-Dateien
|
||||
$VHDXPath = "$VMPath\$VMName.vhdx" # Pfad zur virtuellen Festplatte
|
||||
$ISOPath = "C:\ISO\Win11.iso" # Pfad zur Windows 11 ISO-Datei
|
||||
$SwitchName = "ExternalSwitch" # Name des virtuellen Switches
|
||||
$MemoryStartupMB = 4096 # RAM für die VM (MB)
|
||||
$ProcessorCount = 2 # Anzahl der virtuellen CPUs
|
||||
$DiskSizeGB = 60 # Größe der virtuellen Festplatte (GB)
|
||||
|
||||
# 1. Prüfe, ob der virtuelle Switch existiert
|
||||
if (-not (Get-VMSwitch -Name $SwitchName -ErrorAction SilentlyContinue)) {
|
||||
Write-Host "Erstelle virtuellen Switch '$SwitchName'..." -ForegroundColor Cyan
|
||||
New-VMSwitch -Name $SwitchName -NetAdapterName (Get-NetAdapter | Where-Object { $_.Status -eq 'Up' } | Select-Object -First 1).Name -AllowManagementOS $true
|
||||
}
|
||||
|
||||
# 2. Erstelle das VM-Verzeichnis
|
||||
if (-not (Test-Path -Path $VMPath)) {
|
||||
Write-Host "Erstelle VM-Verzeichnis: $VMPath" -ForegroundColor Cyan
|
||||
New-Item -Path $VMPath -ItemType Directory
|
||||
}
|
||||
|
||||
# 3. Erstelle die virtuelle Festplatte
|
||||
Write-Host "Erstelle virtuelle Festplatte..." -ForegroundColor Cyan
|
||||
New-VHD -Path $VHDXPath -SizeBytes ($DiskSizeGB * 1GB) -Dynamic
|
||||
|
||||
# 4. Erstelle die VM
|
||||
Write-Host "Erstelle die VM '$VMName'..." -ForegroundColor Cyan
|
||||
New-VM -Name $VMName `
|
||||
-MemoryStartupBytes ($MemoryStartupMB * 1MB) `
|
||||
-BootDevice VHD `
|
||||
-VHDPath $VHDXPath `
|
||||
-Path $VMPath `
|
||||
-Generation 2 `
|
||||
-SwitchName $SwitchName
|
||||
|
||||
# 5. Konfiguriere die VM-Hardware
|
||||
Write-Host "Konfiguriere VM-Hardware..." -ForegroundColor Cyan
|
||||
Set-VM -Name $VMName -ProcessorCount $ProcessorCount
|
||||
Set-VM -Name $VMName -DynamicMemory -MinimumBytes 1024MB -MaximumBytes ($MemoryStartupMB * 1MB)
|
||||
|
||||
# 6. ISO einbinden
|
||||
Write-Host "Binde Windows 11 ISO ein..." -ForegroundColor Cyan
|
||||
Add-VMDvdDrive -VMName $VMName -Path $ISOPath
|
||||
|
||||
# 7. Sichere Bootreihenfolge (DVD zuerst)
|
||||
Write-Host "Setze Bootreihenfolge auf DVD-Laufwerk..." -ForegroundColor Cyan
|
||||
Set-VMFirmware -VMName $VMName -FirstBootDevice (Get-VMDvdDrive -VMName $VMName)
|
||||
|
||||
# 8. Starte die VM
|
||||
Write-Host "Starte die VM '$VMName'..." -ForegroundColor Green
|
||||
Start-VM -Name $VMName
|
||||
|
||||
Write-Host "VM '$VMName' wurde erfolgreich erstellt und gestartet!" -ForegroundColor Green
|
||||
Executable
+78
@@ -0,0 +1,78 @@
|
||||
# Variablen
|
||||
$TFTP_Root = "C:\PXE\TFTP"
|
||||
$HTTP_Root = "C:\PXE\HTTP"
|
||||
$KickstartFolder = "$HTTP_Root\kickstarts"
|
||||
$ESXi_ISO = "C:\PXE\ISO\VMware-ESXi.iso"
|
||||
$ExcelFile = "C:\PXE\Config.xlsx"
|
||||
|
||||
# Importiere das Modul "ImportExcel" (offline)
|
||||
$ModulePath = "C:\PXE\Modules"
|
||||
Write-Host "Importiere ImportExcel Modul..." -ForegroundColor Cyan
|
||||
Import-Module "$ModulePath\ImportExcel" -Force
|
||||
|
||||
# Erstelle Verzeichnisstruktur
|
||||
Write-Host "Erstelle Verzeichnisstruktur..." -ForegroundColor Cyan
|
||||
New-Item -Path $TFTP_Root, $HTTP_Root, $KickstartFolder -ItemType Directory -Force
|
||||
|
||||
# Starte TFTP-Server (TFTPD64 offline)
|
||||
Write-Host "Starte TFTP-Server..." -ForegroundColor Cyan
|
||||
Start-Process -FilePath "C:\PXE\TFTPD\tftpd64.exe" -ArgumentList "-d $TFTP_Root" -PassThru
|
||||
|
||||
# HTTP-Server vorbereiten (IIS)
|
||||
Write-Host "Konfiguriere HTTP-Server (IIS)..." -ForegroundColor Cyan
|
||||
Install-WindowsFeature -Name Web-Server -IncludeManagementTools
|
||||
New-WebSite -Name "PXE-HTTP" -PhysicalPath $HTTP_Root -Port 80 -Force
|
||||
|
||||
# Extrahiere ESXi-Boot-Dateien
|
||||
Write-Host "Extrahiere ESXi-Boot-Dateien..." -ForegroundColor Cyan
|
||||
Mount-DiskImage -ImagePath $ESXi_ISO
|
||||
$ISOMount = Get-Volume -FileSystemLabel "ESXI*" | Select-Object -ExpandProperty DriveLetter
|
||||
Copy-Item -Path "$($ISOMount):\efi\*" -Destination $TFTP_Root -Recurse -Force
|
||||
Dismount-DiskImage -ImagePath $ESXi_ISO
|
||||
|
||||
# Kickstart-Dateien erstellen
|
||||
Write-Host "Erstelle Kickstart-Dateien..." -ForegroundColor Cyan
|
||||
$Servers = Import-Excel -Path $ExcelFile
|
||||
foreach ($Server in $Servers) {
|
||||
$MAC = $Server.MAC
|
||||
$IP = $Server.IP
|
||||
$Hostname = $Server.Hostname
|
||||
$Netmask = $Server.Netmask
|
||||
$Gateway = $Server.Gateway
|
||||
$DNS = $Server.DNS
|
||||
$RootPass = $Server.RootPass
|
||||
|
||||
$KickstartFile = "$KickstartFolder\ks_$MAC.cfg"
|
||||
$KickstartContent = @"
|
||||
vmaccepteula
|
||||
rootpw $RootPass
|
||||
install --firstdisk --overwritevmfs
|
||||
network --bootproto=static --ip=$IP --netmask=$Netmask --gateway=$Gateway --nameserver=$DNS --hostname=$Hostname
|
||||
reboot
|
||||
"@
|
||||
Set-Content -Path $KickstartFile -Value $KickstartContent
|
||||
Write-Host "Kickstart-Datei erstellt: ks_$MAC.cfg"
|
||||
}
|
||||
|
||||
# PXE-Menü konfigurieren
|
||||
Write-Host "Erstelle PXE-Boot-Menü..." -ForegroundColor Cyan
|
||||
$PXEConfig = @"
|
||||
DEFAULT menu.c32
|
||||
PROMPT 0
|
||||
TIMEOUT 300
|
||||
MENU TITLE ESXi PXE Boot
|
||||
"@
|
||||
foreach ($Server in $Servers) {
|
||||
$MAC = $Server.MAC
|
||||
$PXEConfig += @"
|
||||
LABEL Install_ESXi_$MAC
|
||||
MENU LABEL Install ESXi - $MAC
|
||||
KERNEL mboot.c32
|
||||
APPEND -c boot.cfg ks=http://192.168.1.100/kickstarts/ks_$MAC.cfg
|
||||
"@
|
||||
}
|
||||
$PXEFolder = "$TFTP_Root\pxelinux.cfg"
|
||||
New-Item -Path $PXEFolder -ItemType Directory -Force
|
||||
Set-Content -Path "$PXEFolder\default" -Value $PXEConfig
|
||||
|
||||
Write-Host "Offline PXE-Server erfolgreich vorbereitet!" -ForegroundColor Green
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
# Module laden
|
||||
Import-Module ImportExcel
|
||||
|
||||
# Excel-Datei einlesen
|
||||
$excelPath = "C:\Pfad\zu\esx_config.xlsx"
|
||||
$hosts = Import-Excel -Path $excelPath -WorksheetName "Tabelle1"
|
||||
|
||||
# Zielverzeichnis für die Kickstart-Dateien
|
||||
$outputDir = "C:\Kickstart-Files"
|
||||
New-Item -ItemType Directory -Path $outputDir -Force | Out-Null
|
||||
|
||||
# Für jeden Host eine Kickstart-Datei generieren
|
||||
foreach ($host in $hosts) {
|
||||
$hostname = $host.Hostname
|
||||
$fqdn = $host.FQDN
|
||||
$ip = $host."Mgmt Net IP"
|
||||
$netmask = $host."Mgnt Netmask"
|
||||
$gateway = $host."vSan GW"
|
||||
$rootPassword = $host."root PW"
|
||||
$vsanIp = $host."vSan IP"
|
||||
$vsanNetmask = $host."vSAN Netmask"
|
||||
$vsanGateway = $host."vSan GW"
|
||||
|
||||
# Kickstart-Inhalt
|
||||
$kickstart = @"
|
||||
vmaccepteula
|
||||
rootpw $rootPassword
|
||||
install --firstdisk --overwritevmfs
|
||||
network --bootproto=static --device=vmnic0 --ip=$ip --netmask=$netmask --gateway=$gateway --hostname=$hostname
|
||||
reboot
|
||||
|
||||
%post --interpreter=busybox
|
||||
# Nach der Installation auszuführende VSAN-Netzwerkkonfiguration
|
||||
esxcli network ip interface add --interface-name=vmk1 --portgroup-name=vSAN
|
||||
esxcli network ip interface ipv4 set --interface-name=vmk1 -I $vsanIp -N $vsanNetmask -g $vsanGateway --type=static
|
||||
%end
|
||||
"@
|
||||
|
||||
# Datei speichern
|
||||
$filePath = Join-Path -Path $outputDir -ChildPath "$hostname-ks.cfg"
|
||||
$kickstart | Out-File -FilePath $filePath -Encoding UTF8
|
||||
Write-Host "Kickstart-Datei für $hostname erstellt: $filePath"
|
||||
}
|
||||
Executable
+53
@@ -0,0 +1,53 @@
|
||||
# PowerCLI-Modul laden
|
||||
Import-Module VMware.PowerCLI
|
||||
|
||||
# Excel-Datei einlesen
|
||||
$excelPath = "C:\Pfad\zu\esx_config.xlsx"
|
||||
$hosts = Import-Excel -Path $excelPath -WorksheetName "Tabelle1"
|
||||
|
||||
# Login-Daten
|
||||
$rootUser = "root"
|
||||
|
||||
# ESXi-Hosts konfigurieren
|
||||
foreach ($host in $hosts) {
|
||||
$hostname = $host.Hostname
|
||||
$fqdn = $host.FQDN
|
||||
$ip = $host."Mgmt Net IP"
|
||||
$netmask = $host."Mgnt Netmask"
|
||||
$gateway = $host."vSan GW"
|
||||
$rootPassword = $host."root PW"
|
||||
$vsanIp = $host."vSan IP"
|
||||
$vsanNetmask = $host."vSAN Netmask"
|
||||
$vsanGateway = $host."vSan GW"
|
||||
$ssh = $host.SSH
|
||||
$lockdown = $host."Lockdown Mode"
|
||||
|
||||
# Verbindung zum Host herstellen
|
||||
Write-Host "Verbinde zu Host $hostname ($ip)..."
|
||||
Connect-VIServer -Server $ip -User $rootUser -Password $rootPassword
|
||||
|
||||
# Hostname setzen
|
||||
Write-Host "Setze Hostname auf $fqdn..."
|
||||
Set-VMHost -VMHost $hostname -Name $fqdn
|
||||
|
||||
# Management-Netzwerk konfigurieren
|
||||
Write-Host "Konfiguriere Management-Netzwerk..."
|
||||
Get-VMHostNetworkAdapter -VMHost $hostname | Set-VMHostNetworkAdapter -IP $ip -SubnetMask $netmask -VMKernelGateway $gateway
|
||||
|
||||
# VSAN konfigurieren
|
||||
Write-Host "Konfiguriere vSAN-Netzwerk..."
|
||||
New-VMHostNetworkAdapter -VMHost $hostname -PortGroup vSAN -IP $vsanIp -SubnetMask $vsanNetmask -VMKernelGateway $vsanGateway -VMotionEnabled $true
|
||||
|
||||
# SSH und Lockdown Mode konfigurieren
|
||||
Write-Host "Konfiguriere SSH und Lockdown Mode..."
|
||||
if ($ssh -eq "enable") {
|
||||
Get-VMHost | Get-VMHostService | Where-Object {$_.Key -eq "TSM-SSH"} | Start-VMHostService
|
||||
}
|
||||
if ($lockdown -eq "enable") {
|
||||
Set-VMHost -VMHost $hostname -LockdownMode $true
|
||||
}
|
||||
|
||||
# Verbindung trennen
|
||||
Disconnect-VIServer -Confirm:$false
|
||||
Write-Host "Host $hostname ($ip) konfiguriert!"
|
||||
}
|
||||
Reference in New Issue
Block a user