VMware Cloud Community
ranjithbabhu
Enthusiast
Enthusiast
Jump to solution

Clone a VM and place in same Resourcepool

Trying to clone a list of VM but unable to place in Same Resourcepool. 

$fileName = '.\clonetask.csv'

$ds = Get-Datastore 

$esx = Get-Cluster| Get-VMHost | Get-Random


Import-Csv -Path $fileName -UseCulture -PipelineVariable row |

ForEach-Object -Process {

New-VM -Name $row.VM_CLONE -VM $row.VM -Datastore $ds -Location (Get-Folder -ID (Get-VM $row.VM).FolderId) -ResourcePool $esx

}|
Export-Csv list71.csv -NoTypeInformation -UseCulture

 

I am able to clone using script but it is not placing the same resourcepool. 

 

Regards

Ranjithbabhu R

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Did you try with first getting the resourcepool from the source VM?

$srcVM = Get-VM -Name $row.VM_CLONE
$rp = Get-ResourcePool -VM $srcVM
New-VM -Name $srcVM -VM $row.VM -Datastore $ds -Location (Get-Folder -ID (Get-VM $row.VM).FolderId) -ResourcePool $rp


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Did you try with first getting the resourcepool from the source VM?

$srcVM = Get-VM -Name $row.VM_CLONE
$rp = Get-ResourcePool -VM $srcVM
New-VM -Name $srcVM -VM $row.VM -Datastore $ds -Location (Get-Folder -ID (Get-VM $row.VM).FolderId) -ResourcePool $rp


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
ranjithbabhu
Enthusiast
Enthusiast
Jump to solution

Thanks LuCD, It work perfect.


$srcVM = Get-VM -Name $row.VM
$rp = Get-ResourcePool -VM $srcVM
New-VM -Name $row.VM_CLONE -VM $row.VM -Datastore $ds -Location (Get-Folder -ID (Get-VM $row.VM).FolderId) -ResourcePool $rp

 

Regards

Ranjthbabhu R

 

0 Kudos