Created
April 8, 2016 14:02
-
-
Save MichaelRyom/db6ce58ba24b1376a38883b48bc93af9 to your computer and use it in GitHub Desktop.
Change VMDK geometry
This file contains hidden or 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
$Path = "C:\Users\Michaelryom\Downloads\VMware\vRealize-Operations-Manager-Appliance-6.1.0.3038036_OVF10\" | |
$vdisk = 'C:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe' | |
$VMDKs = dir $Path*.vmdk | |
cd $path | |
Foreach($VMDK in $VMDKs){ | |
$OldVMDK = $VMDK.Name | |
$NewVMDK = $VMDK.Name -replace(".vmdk","-NEW.vmdk") | |
$TempVMDK = $VMDK.Name -replace(".vmdk","-TEMP.vmdk") | |
$VMDKContent = gc $VMDK -First 25 | |
$TotalSectors = [INT]($VMDKContent | where {$_ -match "RW"}).Split(" ")[1] | |
$cylinders = ($VMDKContent | where {$_ -match "cylinders"}).Split(" ")[2].Replace('"','') | |
$heads = ($VMDKContent | where {$_ -match "heads"}).Split(" ")[2].Replace('"','') | |
$sectors = ($VMDKContent | where {$_ -match "sectors"}).Split(" ")[2].Replace('"','') | |
if($Sectors -ne "63"){ | |
$Newheads = 255 | |
$Newsectors = 63 | |
$Newcylinders = [Math]::floor(($TotalSectors*512)/($Newheads*$Newsectors*512)) | |
.$vdisk -r $OldVMDK -t 1 $TempVMDK | |
try | |
{ | |
$reader = New-Object -typename System.IO.StreamReader -argumentlist $path\$TempVMDK | |
$data = $reader.ReadToEnd() | |
$reader.close() | |
} | |
finally | |
{ | |
if ($reader -ne $null) | |
{ | |
$reader.dispose() | |
} | |
} | |
$data = $data -replace ('ddb.geometry.heads = "'+$heads+'"'),('ddb.geometry.heads = "'+$newheads+'"') -replace ('ddb.geometry.sectors = "'+$sectors+'"'),('ddb.geometry.sectors = "'+$Newsectors+'"') -replace ('ddb.geometry.cylinders = "'+$cylinders+'"'),('ddb.geometry.cylinders = "'+$Newcylinders+'"') | |
try | |
{ | |
$writer = New-Object -typename System.IO.StreamWriter -argumentlist $path\$TempVMDK | |
$writer.write($data) | |
$writer.close() | |
} | |
finally | |
{ | |
if ($writer -ne $null) | |
{ | |
$writer.dispose() | |
} | |
} | |
.$vdisk -r $TempVMDK -t 5 $NewVMDK | |
} | |
dir $TempVMDK.Replace(".vmdk","*.vmdk") | Remove-Item | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment