Created
December 15, 2020 03:44
-
-
Save broestls/2774a8a4d41d621b38c7ec0596f94a7f to your computer and use it in GitHub Desktop.
Generate a VMDK -> VHDX config file for each disk in a VMware VM for use with Starwind V2V CLI
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
# This function creates a cfg file for Starwind V2V converter by getting VM properties from PowerCLI | |
# and writing out a config file per VM disk into a directory named for the VM. | |
# Before executing, define Env variables ESX_USERNAME, ESX_PASSWORD, HV_DEST_HOST, HV_DEST_USERNAME, | |
# and HV_DEST_PASSWORD | |
function Set-V2VConfig { | |
[cmdletbinding()] | |
Param ( | |
[string]$Name, | |
[int[]]$SkipDisks, | |
[string]$DestVol | |
) | |
Process { | |
$vm = Get-VM $Name | |
If (-not $(Test-Path .\$Name)) { | |
New-Item -Path ".\$Name" -ItemType "directory" | |
} | |
If (-not $(Test-Path ".\$vm\convert_$vm.bat")) { | |
$batfile = New-Item -Path ".\$vm\convert_$vm.bat" | |
} | |
$count = 1 | |
foreach ($disk in $(Get-VM $Name | Get-HardDisk)) { | |
If (-not $SkipDisks.Contains($count)) { | |
$cfg = @" | |
in_host_type=esx | |
in_host_address=$($vm.VMhost.Name) | |
in_host_username=$Env:ESX_USERNAME | |
in_host_password=$Env:ESX_PASSWORD | |
in_file_name=$($disk.filename) | |
out_host_type=win | |
out_host_address=$Env:HV_DEST_HOST | |
out_host_username=$Env:HV_USERNAME | |
out_host_password=$Env:HV_PASSWORD | |
out_file_name=$DestVol$vm disk_$count.vhdx | |
out_file_type=ft_vhdx_thin | |
"@ | |
Write-Host "Writing out config file for disk $count" | |
Set-Content -Path ".\$vm\disk$count.cfg" -Value $cfg | |
Add-Content $batfile -Value "V2V_ConsoleConverter.exe -c `".\disk$count.cfg`"" | |
} | |
Else { | |
Write-Host "Skipping disk $count" | |
} | |
$count += 1 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment