Created
October 24, 2022 20:12
-
-
Save AfroThundr3007730/0824579071ea3eef2f8fd06d1b0da718 to your computer and use it in GitHub Desktop.
Edit the metadata header of a VMDK file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Set-StrictMode -Version Latest | |
function Edit-VMDKHeader { | |
<# .SYNOPSIS | |
Edit the metadata header of a VMDK file #> | |
[CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'High')] | |
Param( | |
# The VMDK file to edit | |
[Parameter(Mandatory)] | |
[string]$VMDKFile | |
) | |
$buffer = [byte[]]::new(1024) | |
$tmpFile = [IO.Path]::Combine([IO.Path]::GetTempPath(), [IO.Path]::GetTempFileName()) | |
$vmdkStream = [IO.File]::Open($VMDKFile, [IO.FileMode]::Open, [IO.FileAccess]::ReadWrite) | |
$vmdkStream.Position = 512 | |
[void]$vmdkStream.Read($buffer, 0, 1024) | |
Write-Output 'Dumping VMDK header metadata to:' $tmpFile | |
$tmpStream = [IO.File]::OpenWrite($tmpFile) | |
$tmpStream.Write($buffer, 0, 1024) | |
$tmpStream.Dispose() | |
Write-Output 'Make necessary changes, then save and close the editor.' | |
(Start-Process notepad.exe -ArgumentList $tmpFile -PassThru -Wait).WaitForExit() | |
$tmpStream = [IO.File]::OpenRead($tmpFile) | |
[void]$tmpStream.Read($buffer, 0, 1024) | |
$tmpStream.Dispose() | |
Remove-Item $tmpFile | |
if ($PSCmdlet.ShouldProcess($VMDKFile, 'Overwrite VMDK header metadata')) { | |
Write-Output 'Overwriting VMDK header metadata.' | |
$vmdkStream.Position = 512 | |
$vmdkStream.Write($buffer, 0, 1024) | |
} | |
$vmdkStream.Dispose() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A function implementing the commands from this SO answer to edit VMDK metadata.
This was necessary in order to solve this problem when converting VMDK files to VHDX.