Add PortGroup to all hosts in cluster with PowerCLI

http://discoposse.com/2013/02/14/powercli-add-multiple-vlan-port-groups-to-vsphere-cluster-standard-switches/

Limitations of Standard vSwitches

One of the negative points of standard vSwitches is that there are as many of them as there are ESX hosts and each must be separately created and managed. Add to that, multiple port groups on multiple uplinks and you have a growing administrative challenge.

While we don’t make these types of changes often, it is a change that can take a significant effort. More importantly, it is prone to human error.

Enter PowerCLI

With PowerCLI we have lots of great options. Because our hosts are in a cluster, the process flow will be fairly simple:

  1. Query a file with our VLAN information
  2. Query our vSphere cluster for hosts
  3. Add vSwitch port groups to each host in each cluster

Three easy steps, but the amount of clicks and typing to manually configure all of these port groups would be a real challenge. With a script we ensure consistency of the process.

Your Input File

We are working with a file that is named MyVLANs.csv and is located somewhere that the script can read it from as defined in the script itself. We assign a variable $InputFile and use the full path to find it in our script file.

The file has a header row and the data is organized as shown in our example here:

As we can see, we name the cluster, the vSwitch, the name to apply to the port group (VLANname) and the VLAN number to assign to that port group.

In your environment you could have numerous clusters, and you can use the same source file to manage additions to all of them at the same time.

The Script

I did say it was a three-step process, but one of those steps has a few more activities to perform. That being said, it still isn’t too much to do thanks to PowerCLI.

We assume that you are running your PowerCLI shell with privileges to administer your vCenter environment. This requires access to read the file and to add port groups to the vSphere vSwitches.

First we setup our input file:

$InputFile = “C:UsersewrightDocumentsSCRIPTS-TEMPMyVLANs.csv”

Next we import the file using the handy Import-CSV CmdLet:

$MyVLANFile = Import-CSV $InputFile

Now we just have to parse the contents. Because we have our header row, the columns are already assigned and we just loop through each line using ForEach to read the info, create our PowerCLI command to add the vSwitch and execute.

Because we have to read the cluster information for each line there is another loop inside to add the vSwitch to each host for the cluster.

ForEach ($VLAN in $MyVLANFile) {
$MyCluster = $VLAN.cluster
$MyvSwitch = $VLAN.vSwitch
$MyVLANname = $VLAN.VLANname
$MyVLANid = $VLAN.VLANid

We define variables for each column in the file, then query the cluster for hosts and assign it to the $MyVMHosts variable:

$MyVMHosts = Get-Cluster $MyCluster | Get-VMHost | sort Name | % {$_.Name}

Next we loop through each host, query the vSwitch and create a new port group with the New-VirtualPortGroup CmdLet:

ForEach ($VMHost in $MyVMHosts) {
Get-VirtualSwitch -VMHost $VMHost -Name $MyvSwitch | New-VirtualPortGroup -Name $MyVLANname -VLanId $MyVLANid
}

Here is the view of the whole script, and here is the link to the file: http://www.discoposse.com/wp-content/uploads/AddVLANsToClusterHosts.ps1

About the Errors

One of the things I haven’t done with this script is any error handling. Because I’m only adding switches on occasion it doesn’t need a lot of cleanliness. If you re-run the same file on an existing set of port groups it will throw an error because the port group exists. If I get some extra time I may add a little error housekeeping to clean things up.

Hope this saves you some time. Happy scripting!

时间: 2024-08-24 14:10:13

Add PortGroup to all hosts in cluster with PowerCLI的相关文章

cluster(1)

集群(cluster) (一)集群概念 简单的说,集群就是一组计算机,他们作为一个整体向用户提供一组网络资源.这些单个的计算机系统就是集群的节点(node).集群(一组协同工作的计算机)是充分利用计算资源的一个重要概念,因为它能够将工作负载从一个超载的系统(或节点)迁移到集群中的另一个系统上.常见的硬件有:结点,网络,存储.软件有:机群系统,节点系统,应用支撑软件.集群具有高可用性HA(集群中的一个节点失效,他的任务可传递给其他节点,可以有效防止单点是失效.) (二) 集群系统的分类 一般将集群

Enable Kerberos secured Hadoop cluster with Cloudera Manager

I created an secured Hadoop cluster for P&G with cloudera manager, and this document is to record how to enable kerberos secured cluster with cloudera manager. Firstly we should have a cluster that contains kerberos KDC and kerberos clients 1. Instal

motan源码分析五:cluster相关

上一章我们分析了客户端调用服务端相关的源码,但是到了cluster里面的部分我们就没有分析了,本章将深入分析cluster和它的相关支持类. 1.clustersupport的创建过程,上一章的ReferConfig的initRef()方法中调用了相关的创建代码: for(Iterator iterator = protocols.iterator(); iterator.hasNext();) { ProtocolConfig protocol = (ProtocolConfig)iterat

Arcgis for JS之Cluster聚类分析的实现(基于区域范围的)

原文:Arcgis for JS之Cluster聚类分析的实现(基于区域范围的) 咱们书接上文,在上文,实现了基于距离的空间聚类的算法实现,在本文,将继续介绍空间聚类之基于区域范围的实现方式,好了,闲言少叙,先看看具体的效果: 聚类效果 点击显示信息 显示单个聚类点 下面说说具体的实现思路. 1.数据组织 在进行数据组织的时候,因为是要按照区域范围的,所以必须得包含区域范围的信息,在本示例中,我用的数据依然是全国2000多个区县点的数据,并添加了省市代码,数据如下: 2.聚类思路 根据数据中“p

Arcgis for JS之Cluster聚类分析的实现

原文:Arcgis for JS之Cluster聚类分析的实现 在做项目的时候,碰见了这样一个问题:给地图上标注点对象,数据是从数据库来 的,包含XY坐标信息的,通过graphic和graphiclayer 的方式添加到地图上,其中有一个对象的数量很多,上万了吧,通过上述的方式无法在地图上进行展示,就想到了聚类,当时由于技术和时间的关系,没有实现,最 近,稍微有点先下时间,就又想起这事,继续研究,终于,皇天不负有心人,出来了,出来的第一时间写出来,以便大家使用. 首先,看看实现后的效果: 初始化

管理ONS(Oracle Notification Service)

Onsctl Onsctl这个命令是用来管理ONS(Oracle Notification Service)是OracleClustser实现FAN Event Push模型的基础. Oracle Notification Service (ONS)--A publish and subscribe service for communicating Fast Application Notification (FAN) events. 在RAC环境下,须要使用$CRS_HOME下的ONS,而不

Development of large-scale site performance optimization method from LiveJournal background

A LiveJournal course of development is a project in the 99 years began in the campus, a few people do as a hobby such an application, in order to achieve the following functions: Blog, forum Social network, find friends Polymerization article polymer

Linux Ethernet Bonding Driver HOWTO 英文原版

Linux Ethernet Bonding Driver HOWTO Latest update: 12 November 2007 Initial release : Thomas Davis <tadavis at lbl.gov> Corrections, HA extensions : 2000/10/03-15 : - Willy Tarreau <willy at meta-x.org> - Constantine Gavrilov <const-g at xp

How Network Load Balancing Technology Works--reference

http://technet.microsoft.com/en-us/library/cc756878(v=ws.10).aspx In this section Network Load Balancing Terms and Definitions Network Load Balancing Architecture Network Load Balancing Protocols Application Compatibility with Network Load Balancing