Skip to content

Commit

Permalink
Vsphere-PowerCLI -> drop#1 - powercli script to clone VM from template
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-nath committed Dec 10, 2021
1 parent 8c8ca65 commit 845ae5a
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions powercli/clone_vm.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
. "lib\init.ps1"
. "lib\finalize.ps1"
#. "lib\misc.ps1"

Initialize

$dest_folder = Get-Folder -type VM -name "$pcloud"
Write-Host ">>> Destination folder: $dest_folder`n"
$resourcepool = Get-ResourcePool -Name $resource_pool
Write-Host ">>> ResourcePool: $resourcepool`n"

foreach ($vm in $new_vms)
{
Write-Host ""
$vmo = Get-VM $vm
if (!$?)
{
Write-Host ">>> INFO: Cloning $vm from $clone_from ... " -foregroundcolor "darkcyan"
# $datastore = GetDataStore
# Write-Host ">>> INFO: DataStore to use for Clone-VM - $datastore" -foregroundcolor "darkcyan"
$task = New-VM -Name $vm -Template $template -Location $dest_folder -ResourcePool $resourcepool -Confirm:$false
Write-Host ">>> INFO: Cloning task completed." -foregroundcolor "green"
}
else
{
Write-Host ">>> INFO: VM $vm already exists"
}
}

Finalize

0 comments on commit 845ae5a

Please sign in to comment.