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
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
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
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