Posts tagged: network

Copy vSwitches and Portgroups to everybody in a cluster (like a boss)

Does just what it says, set up one host, and copys everything to the rest of the host, helps me set stuff up faster 🙂

#alan harrington, copy networking one host to another.
$src = Read-Host "Please enter the golden host for networking: "
$destclu = Read-Host "Please enter the name of the cluster to copy too: "
foreach ($dest in (get-cluster $destclu | Get-VMHost)){

$desthost = Get-VMhost $dest
get-vmhost $src | Get-VirtualPortGroup | select VirtualSwitchName,Name,VLanId | export-csv c:\hostnetworking.txt -NoTypeInformation
$infohizzle = import-csv c:\hostnetworking.txt | where-object {$ -notmatch "vmotion" -and $ -notmatch "VMkernel" -and $ -notmatch "Service" -and $ -notmatch "Management Network"}

$infohizzle | % {
$Vportgrp = $_.Name
$vswitch = $_.VirtualSwitchName
$vlan = $_.VlanId

If (($desthost |Get-Virtualportgroup -Name $Vportgrp -ErrorAction SilentlyContinue)-eq $null){
if (($desthost |Get-VirtualSwitch -Name $vswitch -ErrorAction SilentlyContinue)-eq $null){$desthost | New-VirtualSwitch -Name $vswitch}
$desthost | Get-VirtualSwitch -Name $vswitch | New-VirtualPortGroup -ErrorAction "SilentlyContinue" -Name $Vportgrp -VLanId $vlan}}}

WordPress Themes