<# .SYNOPSIS Bölüm 00 · Adım 0.2 — Hyper-V Varsayılan Yolları ve İzole NAT Sanal Ağı (Lab-Internal-NAT) .DESCRIPTION Hyper-V varsayılan VM/VHDX dizinlerini D:\Lab\VMs konumuna yönlendirir, Internal tipinde Lab-Internal-NAT sanal anahtarını kurar, ana bilgisayara 10.10.20.1/24 Gateway IP'sini atar ve 10.10.20.0/24 alt ağı için Windows yerleşik NAT (Lab-NAT) yönlendirmesini etkinleştirir. .EXAMPLE powershell -ExecutionPolicy Bypass -File "D:\Lab\Scripts\01-Setup-LabNetwork.ps1" #> #Requires -RunAsAdministrator param( [string]$LabRoot = "D:\Lab", [string]$SwitchName = "Lab-Internal-NAT", [string]$NatName = "Lab-NAT", [string]$SubnetPrefix = "10.10.20" ) $ErrorActionPreference = "Stop" $GatewayIP = "$SubnetPrefix.1" $SubnetCIDR = "$SubnetPrefix.0/24" if ((Get-Service -Name vmms -ErrorAction SilentlyContinue).Status -ne 'Running') { throw "Hyper-V Virtual Machine Management (vmms) servisi çalışmıyor. Adım 0.1 sonrası bilgisayarı yeniden başlattığınızdan emin olun." } Write-Host "[1/4] Hyper-V varsayılan VM ve VHDX yolları ayarlanıyor: $LabRoot\VMs" -ForegroundColor Cyan Set-VMHost -VirtualHardDiskPath "$LabRoot\VMs" -VirtualMachinePath "$LabRoot\VMs" Write-Host "[2/4] Internal sanal anahtar kontrol ediliyor: $SwitchName" -ForegroundColor Cyan if (-not (Get-VMSwitch -Name $SwitchName -ErrorAction SilentlyContinue)) { New-VMSwitch -SwitchName $SwitchName -SwitchType Internal | Out-Null } $Adapter = Get-NetAdapter -Name "vEthernet ($SwitchName)" -ErrorAction Stop $IfIndex = $Adapter.IfIndex Write-Host "[3/4] Gateway IP ($GatewayIP/24) ve WinNAT ($SubnetCIDR) yapılandırılıyor..." -ForegroundColor Cyan if (-not (Get-NetIPAddress -InterfaceIndex $IfIndex -IPAddress $GatewayIP -ErrorAction SilentlyContinue)) { New-NetIPAddress -IPAddress $GatewayIP -PrefixLength 24 -InterfaceIndex $IfIndex | Out-Null } $ExistingNat = Get-NetNat -ErrorAction SilentlyContinue if (-not ($ExistingNat | Where-Object { $_.Name -eq $NatName })) { if ($ExistingNat) { throw "Windows 10/11 üzerinde zaten '$($ExistingNat.Name)' adlı bir NetNat nesnesi var ($($ExistingNat.InternalIPInterfaceAddressPrefix)). Önce 'Get-NetNat' ile inceleyip kullanılmıyorsa 'Remove-NetNat -Name $($ExistingNat.Name)' ile kaldırın." } New-NetNat -Name $NatName -InternalIPInterfaceAddressPrefix $SubnetCIDR | Out-Null } Write-Host "[4/4] Başarı kontrolü çıktısı:" -ForegroundColor Green Get-VMHost | Select-Object ComputerName, VirtualMachinePath, VirtualHardDiskPath | Format-List Get-NetNat | Format-Table Name, InternalIPInterfaceAddressPrefix, Active -AutoSize Get-NetIPAddress -InterfaceIndex $IfIndex -AddressFamily IPv4 | Format-Table InterfaceAlias, IPAddress, PrefixLength -AutoSize