VMware Cloud Community
mcamp001
Contributor
Contributor
Jump to solution

Clone multiple VMs and append names

Hi,

  I see several examples of this, but I am struggling with the correct syntax to do the following:

  • Clone multiple VM's from a text file.

  • Append "-clone" to each name of the clones, example=vm1 clones as vm1-clone

I can use the following to do a simple clone:

New-VM -Name VM2 -VM VM1 -Datastore datastorename -vmhost hostname -DiskStorageFormat thin

but want to further automate the other pieces.

Any insight is appreicated!

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

If your text file is setup as a CSV file, you can do something like this

Import-Csv C:\text.csv -UseCulture | %{

     New-VM -Name ($_.Name + "-clone") -VM $_.Name -Datastore datastorename -vmhost hostname -DiskStorageFormat thin

}

This assumes your CSV file looks something like this

Name

VM1

VM2

VM3


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

If your text file is setup as a CSV file, you can do something like this

Import-Csv C:\text.csv -UseCulture | %{

     New-VM -Name ($_.Name + "-clone") -VM $_.Name -Datastore datastorename -vmhost hostname -DiskStorageFormat thin

}

This assumes your CSV file looks something like this

Name

VM1

VM2

VM3


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

0 Kudos
mcamp001
Contributor
Contributor
Jump to solution

Luc, as always, Thank You..

+ "-clone" this is what I couldn't seem to get correct..

Cheers!

0 Kudos