6.2

Table Of Contents
{
write-host -ForeGroundColor Red "CSV File $CSVFile not found"
exit
}
# Connect to the VC (Parameterize VC)
#Write-Host "DisConnecting Previous Connections"
#Disconnect-VIServer * -Confirm:$false -ErrorAction SilentlyContinue
Write-Host "Connecting to VC $vcAddress"
Connect-VIServer $vcAddress -ErrorAction Stop -user $vcAdmin -password $vcPassword
#Read input CSV file
$csvData = Import-CSV $csvFile
#$csvData = Import-CSV $csvFile -
header("VMName","Parentvm","CustomSpec","Datastore","Host","FromSnapshot","DeleteIfPresent")
foreach ($line in $csvData)
{
$destVMName=$line.VMName
$srcVM = $line.Parentvm
$cSpec = $line.CustomSpec
$targetDSName = $line.Datastore
$destHost = $line.Host
$srcSnapshot = $line.FromSnapshot
$deleteExisting = $line.DeleteIfPresent
if (IsVMExists ($destVMName))
{
Write-Host "VM $destVMName Already Exists in VC $vcAddress"
if($deleteExisting -eq "TRUE")
{
Delete_VM ($destVMName)
}
else
{
Write-Host "Skip clone for $destVMName"
continue
}
}
$vm = get-vm $srcvm -ErrorAction Stop | get-view -ErrorAction Stop
$cloneSpec = new-object VMware.VIM.VirtualMachineCloneSpec
$cloneSpec.Location = new-object VMware.VIM.VirtualMachineRelocateSpec
if ($CloneType -eq "linked")
{
$cloneSpec.Location.DiskMoveType =
[VMware.VIM.VirtualMachineRelocateDiskMoveOptions]::createNewChildDiskBacking
}
Write-Host "Using Datastore $targetDSName"
$newDS = Get-Datastore $targetDSName | Get-View
$CloneSpec.Location.Datastore = $newDS.summary.Datastore
Set-VM -vm $srcVM -snapshot (Get-Snapshot -vm $srcVM -Name $srcSnapshot) -confirm:$false
$cloneSpec.Snapshot = $vm.Snapshot.CurrentSnapshot
$cloneSpec.Location.Host = (get-vmhost -Name $destHost).Extensiondata.MoRef
$CloneSpec.Location.Pool = (Get-ResourcePool -Name Resources -Location (Get-VMHost -Name
$destHost)).Extensiondata.MoRef
# Start the Clone task using the above parameters
Setting Up Horizon 6 for Linux Desktops
38 VMware, Inc.