{"id":510,"date":"2014-02-25T15:57:29","date_gmt":"2014-02-25T15:57:29","guid":{"rendered":"http:\/\/giraffeit.com\/?p=510"},"modified":"2014-02-25T15:57:29","modified_gmt":"2014-02-25T15:57:29","slug":"esxclone","status":"publish","type":"post","link":"https:\/\/giraffeit.com\/index.php\/2014\/02\/25\/esxclone\/","title":{"rendered":"VMware ESX network cloning"},"content":{"rendered":"<p>Ever wanted to clome your network settings across multiple ESX hosts ?<\/p>\n<p>&nbsp;<\/p>\n<p>Execute this first :<\/p>\n<p>Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue<\/p>\n<p>&nbsp;<\/p>\n<p>That adds in the relevant Powershell tools save you having to use PowerCLi<\/p>\n<p>&nbsp;<\/p>\n<p>Then copy and paste this into a .ps1 file<\/p>\n<p>&nbsp;<\/p>\n<p>$srvconnection = Connect-VIServer (Read-Host &#8220;Please enter the name of your VCenter SERVER&#8221;)<br \/>\n$sourceHost = Get-VMHost -Name (Read-Host &#8220;Enter the name of your existing server as seen in the VI Client Source:&#8221;)<br \/>\n$targetHost = Get-VMHost -Name (Read-Host &#8220;Enter the name of the server to configure as seen in the VI Target Client:&#8221;)<\/p>\n<p>#Collecting source information<br \/>\n$sourceHostObj = Get-VMHost -Name $sourceHost -Server $srvconnection<br \/>\nwrite-host \u201cExporting vSwithes configurations from $sourceHost\u201d<br \/>\n$sourcevSwitches = $sourceHostObj | Get-VirtualSwitch<br \/>\nwrite-host \u201cExporting Port Group configurations from $targetHost\u201d<br \/>\n$sourcevPGs = $sourceHostObj | Get-VirtualPortGroup<\/p>\n<p>#Collecting target host information<br \/>\n$targethostObj = Get-VMHost -Name $targetHost -Server $srvconnection<br \/>\nwrite-host \u201cExporting vSwithes configurations of target $targetHost\u201d<br \/>\n$targetvSwitches = $targetHostObj | Get-VirtualSwitch<br \/>\nwrite-host \u201cExporting Port Group configurations of target $targetHost\u201d<br \/>\n$targetvPGs = $targetHostObj | Get-VirtualPortGroup<\/p>\n<p># determine the difference<br \/>\n$differencevSwitches = Compare-Object $sourcevSwitches $targetvSwitches<br \/>\n$differencevPGs = Compare-Object $sourcevPGs $targetvPGs<\/p>\n<p># Only process the difference in vSwitches<br \/>\n$differencevSwitches | %{<br \/>\n$newvSwitch = $_.InputObject<br \/>\nWrite-Host \u201cCreating Virtual Switch $($newvSwitch.Name) on $targetHost\u201d<br \/>\nif($newvSwitch.Nic) {<br \/>\n$outputvSwitch = $targethostObj | New-VirtualSwitch -Name $newvSwitch.Name -NumPorts $newvSwitch.NumPorts -Mtu $newvSwitch.Mtu -Nic $newvSwitch.Nic<br \/>\n} else {<br \/>\n$outputvSwitch = $targethostObj | New-VirtualSwitch -Name $newvSwitch.Name -NumPorts $newvSwitch.NumPorts -Mtu $newvSwitch.Mtu<br \/>\n}<br \/>\n}<\/p>\n<p># Only Process difference in Port Groups<br \/>\n$differencevPGs | %{<br \/>\n$newvPG = $_.InputObject<br \/>\nWrite-Host \u201cCreating Port group \u201c\u201d$($newvPG.Name)\u201d&#8221; on vSwitch \u201c\u201d$($newvPG.VirtualSwitchName)\u201d&#8221; on target host $targetHost\u201d<br \/>\n$outputvPG = $targethostObj | Get-VirtualSwitch -Name $newvPG.VirtualSwitchName | New-VirtualPortGroup -Name $newvPG.Name-VLanId $newvPG.VLanID<br \/>\n}<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>Only thing to note is it creates the VMotion ports incorrectly , delete them and add them as a VMKernel port.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Ever wanted to clome your network settings across multiple ESX hosts ? &nbsp; Execute this first : Add-pssnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue &nbsp; That adds in the relevant Powershell tools save you having to use PowerCLi &nbsp; Then copy and paste this into a .ps1 file &nbsp; $srvconnection = Connect-VIServer (Read-Host &#8220;Please enter the name of &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/giraffeit.com\/index.php\/2014\/02\/25\/esxclone\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;VMware ESX network cloning&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":["post-510","post","type-post","status-publish","format-standard","hentry","category-bog"],"_links":{"self":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/510","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/comments?post=510"}],"version-history":[{"count":0,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/posts\/510\/revisions"}],"wp:attachment":[{"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/media?parent=510"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/categories?post=510"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/giraffeit.com\/index.php\/wp-json\/wp\/v2\/tags?post=510"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}