Hi all-
I know this has been covered previously via other posts, such as:
and
https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Clone-a-VM-with-a-script/td-p/509187
But it seems like those situations vary just enough that it throws me off of what I'm trying to accomplish. I'm trying to automate the following procedure that I currently do for clones. It's time consuming, to say the least. I currently do these steps in vSphere:
So I have VMs that I want to clone, appending their names, sourced from different datastores and folders, all being cloned to the same folder and datastore.
Any help getting this straight in my brain would be helpful.
Austin
I don't see anything unusual in your scenario.
The first thing to define, how would the variable data (VM, folder, cluster and datastore) be transmitted to a script?
Is that information available in a file (for example a CSV)?
Or do you want the script to prompt for that information?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
LucD-
Thanks so much for the reply. I could put the info into a CSV fairly easily. The less I have to do once the script is running, the better. I'm looking to do less manual input with cloning so the CSV route is ideal 🙂
Try something like this.
I used splatting to avoid a long line of parameters on the New-VM cmdlet.
# CSV layout
#
#VM,Cluster,Datastore,Folder
#VM1,MyCluster,MyDS1,Clones
#VM2,MyCluster,MyDS2,Clones
Import-Csv -Path .\clone.csv -UseCulture |
ForEach-Object -Process {
$sClone = @{
VM = $_.VM
ResourcePool = $_.Cluster
Datastore = $_.Datastore
Name = "$($_.VM)_clone_$(Get-Date -Format 'MMddyyyy')"
Location = $_.Folder
Confirm = $false
}
New-VM @sClone
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference