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
|
||||
Reference in New Issue
Block a user