{"id":1573,"date":"2021-01-18T19:49:20","date_gmt":"2021-01-19T00:49:20","guid":{"rendered":"https:\/\/enterpriseadmins.org\/blog\/?p=1573"},"modified":"2021-01-18T19:49:20","modified_gmt":"2021-01-19T00:49:20","slug":"clone-template-to-new-vcenter","status":"publish","type":"post","link":"https:\/\/enterpriseadmins.org\/blog\/scripting\/clone-template-to-new-vcenter\/","title":{"rendered":"Clone Template to new vCenter"},"content":{"rendered":"\n<p>On a recent TAM Lab session (<a href=\"https:\/\/www.youtube.com\/watch?v=o5e9vXj0zAc&amp;feature=youtu.be\">TAM Lab 082<\/a>) I covered several methods for managing vSphere templates.  At the end of the presentation we had a brief bonus method that showed using PowerCLI to clone a template to a different vCenter.  This could be used once you update your primary copy of a template in vCenter1 and you wanted to make that template available in a different environment.  The script used in the demo is available below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$creds = Get-Credential\n\n$sourceVC = Connect-ViServer t036-vcsa-01.lab.enterpriseadmins.org -Credential $creds\n$destVC   = Connect-ViServer core-vcenter01.lab.enterpriseadmins.org -Credential $creds\n\n$destTemplateName = 'template-tinycore11.1_tamlabtest'\n$splatNewVM = @{\n  Name     = $destTemplateName\n  Template = 'template-tinycore11.1'\n  VMHost   = 't036-vesx-01.lab.enterpriseadmins.org'\n}\n$vm = New-VM @splatNewVM -Server $sourceVC\n\n$splatMoveVM = @{\n  VM                = $vm\n  NetworkAdapter    = (Get-NetworkAdapter -VM $vm -Server $sourceVC)\n  PortGroup         = (Get-VirtualPortGroup -Name 'VLAN10' -Server $destVC)\n  Destination       = (Get-VMHost 'test-esx-33.lab.enterpriseadmins.org' -Server $destVC)\n  Datastore         = (Get-Datastore 'test-esx-33_nvme' -Server $destVC)\n  InventoryLocation = (Get-Folder 'vc1_TAMLab082' -Server $destVC)\n}\nMove-VM @splatMoveVM\n\nGet-VM $destTemplateName -Server $destVC | \nSet-VM -Name 'template-tinycore11.1-bonus' -ToTemplate -Confirm:$false<\/code><\/pre>\n\n\n\n<p>This script uses splatting to improve readability.  You can read more <a href=\"https:\/\/docs.microsoft.com\/en-us\/powershell\/module\/microsoft.powershell.core\/about\/about_splatting?view=powershell-7.1\">about_Splatting here<\/a>.  There are a couple basic components.  First we connect to both vCenters, in this case using the same credentials.  We then create a new VM from template on the source side, then move that VM to the destination side, and finally rename the destination VM and convert it to a template.  We did this as multiple steps as <code>Move-VM<\/code> has additional parameters to assist with changing the destination network adapter to specify the correct portgroups and such.  <\/p>\n","protected":false},"excerpt":{"rendered":"<p>On a recent TAM Lab session (TAM Lab 082) I covered several methods for managing vSphere templates. At the end of the presentation we had a brief bonus method that showed using PowerCLI to clone a template to a different &hellip; <a href=\"https:\/\/enterpriseadmins.org\/blog\/scripting\/clone-template-to-new-vcenter\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3,4],"tags":[],"class_list":["post-1573","post","type-post","status-publish","format-standard","hentry","category-scripting","category-virtualization"],"_links":{"self":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1573","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/comments?post=1573"}],"version-history":[{"count":2,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1573\/revisions"}],"predecessor-version":[{"id":1575,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/posts\/1573\/revisions\/1575"}],"wp:attachment":[{"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/media?parent=1573"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/categories?post=1573"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enterpriseadmins.org\/blog\/wp-json\/wp\/v2\/tags?post=1573"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}