Skip to content

Instantly share code, notes, and snippets.

@vmnomad
Last active May 4, 2017 13:05
Replacing virtual machine disk UUID
<#
.SYNOPSIS
This script allows to create replica seeds for vSphere Replication without powering off the source VM and keeping identical UUID
.NOTES
File Name : xMove-VM.ps1
Author : Askar Kopbayev - @akopbayev
Version : 1.0
.LINK
http://vmnomad.blogspot.com/creatingreplicaseedsforpoweredOnVMs.html
.LINK
https://github.com/vmnomad
#>
$vdm = get-view -id (get-view serviceinstance).content.virtualdiskmanager
# Get Datatcenter
$dc=get-datacenter
# Get Original VM
$sourceVM = get-folder -name Source | get-VM -name TestVM
# Get VM Clone
$destVM = get-folder -Name Clone | get-VM -name $SourceVM.Name
# Get VM disks
$SourceHDs = $SourceVM | Get-HardDisk
$DestHDs = $DestVM | Get-HardDisk
# replace destination disk UUID
for($i=0; $i -lt $sourceHDs.count; $i++) {
# retrieve UUID of the original disk
$SourceUUID = $vdm.queryvirtualdiskuuid($SourceHDs[$i].filename , $dc.id)
# Assigning original UUID to the cloned disk
$vdm.setVirtualDiskUuid($DestHDS[$i].filename, $dc.id, $SourceUUID)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment