Hyper-V

Convert Dynamic VHDX to Fixed VHDX

function Convert-VMDisksToFixed {
    param (
        [Parameter(Mandatory)]
        [string]$VMName,

        [Parameter(Mandatory)]
        [array]$Disks  # Her disk için @{Old="..." ; New="..."}
    )

    # VM SID bul
    try {
        $vmId = (Get-VM $VMName).Id.Guid
        $vmSid = "NT VIRTUAL MACHINE\$vmId"
    } catch {
        Write-Error "❌ VM '$VMName' bulunamadı."
        return
    }

    foreach ($disk in $Disks) {
        $oldPath = $disk.Old
        $newPath = $disk.New

        if (-not (Test-Path $oldPath)) {
            Write-Warning "⚠️ Disk bulunamadı: $oldPath"
            continue
        }

        $vhdInfo = Get-VHD -Path $oldPath

        if ($vhdInfo.VhdType -ne 'Fixed') {
            Write-Host "`n🔄 Converting to fixed: $oldPath -> $newPath"
            Convert-VHD -Path $oldPath -DestinationPath $newPath -VHDType Fixed -ErrorAction Stop
            Remove-Item -Path $oldPath -Force
        } else {
            Write-Host "`n🔁 Already fixed: Renaming $oldPath -> $newPath"
            Rename-Item -Path $oldPath -NewName (Split-Path $newPath -Leaf)
        }

        # NTFS izinlerini ayarla
        try {
            $acl = Get-Acl $newPath
            $accessRule = New-Object System.Security.AccessControl.FileSystemAccessRule($vmSid, "FullControl", "Allow")
            $acl.AddAccessRule($accessRule)
            Set-Acl -Path $newPath -AclObject $acl
            Write-Host "✅ NTFS izinleri eklendi: $vmSid → $newPath"
        } catch {
            Write-Warning "❌ İzin ayarlanamadı: $newPath - $_"
        }
    }

    Write-Host "`n🎯 İşlem tamamlandı."
}

Usage

Find&Move Orphand Virtual Hard Disk Files

Usage

Grant-VMVhdPermission

Usage

Last updated