- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The code I'm using actually came with another module to migrate the templates after they were converted to VMs, and I re-instated the module and it actually migrates the VMs with no issues. Here it is:
Call the new module using this line:
# $MoveVMToDS = Move-VM -VM (Get-VM -Name $oTemplateAsVM) -Datastore ($TargetDS) -Confirm:$false -ErrorAction Stop
Move-VMThin (Get-VM $oTemplateAsVM) (Get-Datastore $TargetDS)
function Move-VMThin
{
PARAM(
[Parameter(Mandatory=$true,ValueFromPipeline=$true,HelpMessage="Virtual Machine Objects to Migrate")]
[ValidateNotNullOrEmpty()]
[System.String]$VM,
[Parameter(Mandatory=$true,HelpMessage="Destination Datastore")]
[ValidateNotNullOrEmpty()]
[System.String]$Datastore
)
Begin
{
#Nothing Necessary to process
} #Begin
Process
{
#Prepare Migration info, uses .NET API to specify a transformation to thin disk
$vmView = Get-View -ViewType VirtualMachine -Filter @{"Name" = "$VM"}
$dsView = Get-View -ViewType Datastore -Filter @{"Name" = "$Datastore"}
#Abort Migration if free space on destination datastore is less than 50GB
if (($dsView.info.freespace / 1GB) -lt 50) {throw "Move-ThinVM ERROR: Destination Datastore $Datastore has less than 50GB of free space. This script requires at least 50GB of free space for safety. Please free up space or use the VMWare Client to perform this Migration"}
#Prepare VM Relocation Specificatoin
$spec = New-Object VMware.Vim.VirtualMachineRelocateSpec
$spec.datastore = $dsView.MoRef
$spec.transform = "sparse"
#Perform Migration
$vmView.RelocateVM($spec, $null)
$MoveResult = Move-VM -VM $VM -Datastore $Datastore
} #Process
}
Actually, this was a code module posted by you in this thread a while back:
So I really would love to know why the original Move-VM would migrate the template-convertedTo-VM and ALSO produce an error (Operation is not valid due to the current state of the object.).