Advertisement
Merzavets

VMware: Copy VLANs from one esx to another

Mar 15th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # $VISRV = Connect-VIServer (Read-Host "Please enter the name of your VI SERVER")
  2. # $BASEHost = Get-VMHost -Name (Read-Host "Please enter the name of your existing server as seen in the VI Client:")
  3. # $NEWHost = Get-VMHost -Name (Read-Host "Please enter the name of the server to configure as seen in the VI Client:")
  4.  
  5. $BASEHost = Get-VMHost -Name 'esx5'
  6. $NEWHost = Get-VMHost -Name 'esx4'
  7.  
  8. $BASEHost |Get-VirtualSwitch |Foreach {
  9.    If (($NEWHost |Get-VirtualSwitch -Name $_.Name -ErrorAction SilentlyContinue) -eq $null){
  10.        Write-Host "Creating Virtual Switch $($_.Name)"
  11.        $NewSwitch = $NEWHost |New-VirtualSwitch -Name $_.Name -NumPorts $_.NumPorts -Mtu $_.Mtu
  12.     }
  13.     $vSwitch = $_
  14.     $_ |Get-VirtualPortGroup |Foreach {
  15.        If (($NEWHost |Get-VirtualPortGroup -Name $_.Name -ErrorAction SilentlyContinue) -eq $null){
  16.            Write-Host "Creating Portgroup $($_.Name)"
  17.            $NewPortGroup = $NEWHost |Get-VirtualSwitch -Name $vSwitch |New-VirtualPortGroup -Name $_.Name -VLanId $_.VLanID
  18. #          -whatif
  19.         }
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement