VMware Cloud Community
Gaprofitt17
Enthusiast
Enthusiast
Jump to solution

Cloning VMs to alternate datastore

I'm trying to clone a list of VM's to an alternate datastore, I have a list of VM's in a .CSV file.

 

## Connect-VIServer vcenter.server
$VMHost = "hostname.test"

$srcvms = Import-Csv -Path ./Documents/vmnames.csv -UseCulture | select -ExpandProperty VM

Foreach ($srcvm in $srcvms) {

new-vm -name "clone_$srcvm" -VM $srcvm -VMHost $VMHost -Datastore "test" -DiskStorageFormat Thin -RunAsync

}
 
My variable returns hostname.test, I am connected to my vCenter, but it's barking about the $VMhost variable..
 
new-vm -name "clone_$srcvm" -VM $srcvm -VMHost '$VMHost'
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 5/9/2022 12:52:48 PM New-VM Please specify at least one of the following parameters: "ResourcePool" or "VMHost".
 
All the hosts have the test datastore mounted, can I forego the VMhost requirement or what am I doing wrong?
 
Thanks,
 
Greg
Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Did you already try with changing that line to

$VMHost = Get-VMHost -Name "hostname.test"

 

Adding the Verbose switch, and/or the WhatIf switch, on the New-VM cmdlet might provide some more feedback.
For testing I would in any case remove the RunAsync switch


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

View solution in original post

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Did you already try with changing that line to

$VMHost = Get-VMHost -Name "hostname.test"

 

Adding the Verbose switch, and/or the WhatIf switch, on the New-VM cmdlet might provide some more feedback.
For testing I would in any case remove the RunAsync switch


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

Reply
0 Kudos
Gaprofitt17
Enthusiast
Enthusiast
Jump to solution

That worked.  Thanks a bunch..

Reply
0 Kudos