PoshCode Archive  Artifact [30a7b45202]

Artifact 30a7b45202bb774b2bcd43f264f95e06138850900d555a66ca5b9453355840a4:

  • File Step04-Copy_VLAN_clust.ps1 — part of check-in [3845df3085] at 2018-06-10 13:59:41 on branch trunk — Script to copy standard vSwitch config across all host within the cluster (user: Leon Scheltema size: 1657)

# encoding: ascii
# api: powershell
# title: Step04-Copy_VLAN_clust
# description: Script to copy standard vSwitch config across all host within the cluster
# version: 0.1
# type: script
# author: Leon Scheltema
# license: CC0
# x-poshcode-id: 5705
# x-archived: 2015-01-25T23:11:53
# x-published: 2015-01-23T12:59:00
#
#
# Script to copy standard vSwitch config across all host within the cluster
# Modified by Leon Scheltema AVANCE ICT Groep Nederland

# Begin variables
$sourceVI = "New vCenter"
$BASEHost = "Base host"
# End variables

# Connect to vCenter server
Connect-VIServer "$sourceVI"

$NEWHost = Get-Cluster "Base host Cluster" | Get-VMhost

Foreach ($hosts in $NEWHost) {
Get-VMHost -Name $BASEHost |Get-VirtualSwitch |Foreach {
   If ((Get-VMHost -Name $hosts |Get-VirtualSwitch -Name $_.Name-ErrorAction SilentlyContinue)-eq $null){
       Write-Host "Creating Virtual Switch $($_.Name)"
       $NewSwitch = Get-VMHost -Name $hosts |New-VirtualSwitch -Name $_.Name-NumPorts $_.NumPorts-Mtu $_.Mtu
       $vSwitch = $_
                    }
                   $_ |Get-VirtualPortGroup |Foreach {
                       If ((Get-VMHost -Name $hosts |Get-VirtualPortGroup -Name $_.Name-ErrorAction SilentlyContinue)-eq $null){
                           Write-Host "Creating Portgroup $($_.Name)"
                           $NewPortGroup = Get-VMHost -Name $hosts |Get-VirtualSwitch -Name $vSwitch |New-VirtualPortGroup -Name $_.Name-VLanId $_.VLanID
                        }
                    }
}
}

# Disconnect from vCenter server
Disconnect-VIServer -server "$sourceVI" -Force -Confirm:$false