Scripts for configure portgroup

Export portgroup from the host

Add-PSSnapin vmWARE.VimAutomation.Core

$vc="Vcname"
connect-viserver $vc
$date = Get-Date -Format ‘yyyyMMdd‘

 $VLANinfo = foreach ($cluster in get-cluster)
       {
            foreach ($esx in (Get-VMHost -Location $cluster))
       {
            foreach ($pg in (Get-VirtualPortGroup -VMHost $esx))

       {
         Select-Object -InputObject $pg -Property @{N="Cluster"; E={$cluster.Name}},
                                    @{N="VMhost";  E={$esx.Name}},
                                    @{N="VirtualSwitchName"; E={$pg.VirtualSwitchName}},
                                    @{N="portgroup"; E={$pg.Name}},
                                    @{N="VLAN";      E={$pg.VlanID}}
                }
                }
                }

$VLANinfo | Export-Csv "C:\PS\report\$($vc)_allPortGroup_$date.csv"

Import portgroup to the host

CSV format



Script


#[cluster,vSwitch,VLANname,VLANid]

#e.g: cluster name,vSwitch0,VM_network,192.168.0.0,11

Add-PSSnapin vmWARE.VimAutomation.Core

$vc="vcntername"
connect-viserver $vc

#Set the input file

$InputFile = "C:\PS\Import_PortGroup\All_PortGroup_SIT_20161202.csv"

#Read the import file

$MyVLANFile = Import-CSV $InputFile

#Parse the input file and add the virtual port groups accordingly

ForEach ($VLAN in $MyVLANFile) {

  $MyCluster = $VLAN.cluster

  $MyvSwitch = $VLAN.vSwitch

  $MyVLANname = $VLAN.VLANname

  $MyVLANid = $VLAN.VLANid

 #Query the cluster to retrieve the hosts

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

#Loop through the hosts and add the virtual port group to our vswitch based on the input

  ForEach ($VMHost in $MyVMHosts) {

  Get-VirtualSwitch -VMHost $VMHost -Name $MyvSwitch | New-VirtualPortGroup -Name $MyVLANname -VLanId $MyVLANid

  }

}

Copy vSwith portgroup from an existing ESXi host

Script


##http://www.virtu-al.net/2009/06/27/powercli-easy-vswitch-portgroup-setup/
##copying all vSwitches and PortGroups from an existing ESX server over to a new server

Add-PSSnapin vmWARE.VimAutomation.Core

$VISRV = Connect-VIServer (Read-Host "Please enter the name of your VI SERVER")
$BASEHost = Get-VMHost -Name (Read-Host "Please enter the name of your existing server as seen in the VI Client:")
$NEWHost = Get-VMHost -Name (Read-Host "Please enter the name of the server to configure as seen in the VI Client:")

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

Remove VirtualPortGroup Specify vSwitch

#Remove all port groups on speific vSwitch#

Add-PSSnapin vmWARE.VimAutomation.Core

Connect-VIServer VCName

$hostserver = "10.194.194.80"

$virtualsw = Get-virtualswitch -vmhost $hostserver -Name vSwitch0

#$vswgoup = Get-VirtualPortGroup -VMHost 10.194.96.1 -VirtualSwitch $virtualsw | where { $_.Name -ne  "Management Network" }

$vswgoup = Get-VirtualPortGroup  -VirtualSwitch $virtualsw | where { $_.Name -ne  "Management Network" }

$vswgoup | Remove-VirtualPortGroup -confirm:$false

Disconnect-VIServer VCName

原文地址:http://blog.51cto.com/549687/2114717

时间: 2024-11-11 13:45:48

Scripts for configure portgroup的相关文章

Scripts for configure VM

How to batch extend VM disk Add-PSSnapin vmWARE.VimAutomation.Core $vc="vCenterHostName" connect-viserver $vc $VMinfo = get-content "c:\VMName.csv" foreach ($VM in $VMinfo){ Get-HardDisk -vm $VM | where {$_.Name -eq "Hard Disk 1&q

Configure,Makefile.am, Makefile.in, Makefile

无论对于一个初学者还是一个资深的Linux程序员,编写Makefile文件都是一件很麻烦的事:再者,开发人员应该把主要的精力放在程序代码的编写上,而在Makefile文件花费太多的精力显然是不明智的:还有,对于不同的处理器架构,往往编译器不同,环境不同,特别是一些嵌入式系统中的各种程序的编译,于是移植问题也使Makefile文件编写趋于复杂,也显得这个问题很重要.对于这些问题Linux的高手们早已想到了,所以他们开发了一些能够自动生成Makefile文件的工具.他们就是下面这些工具: 〉GNU

Configure,make,make install详解

转:http://my.oschina.net/qihh/blog/66113?fromerr=6ej3CfGJ 无论对于一个初学者还是一个资深的Linux程序员,编写Makefile文件都是一件很麻烦的事:再者,开发人员应该把主要的精力放在程序代码的编写上,而在Makefile文件花费太多的精力显然是不明智的:还有,对于不同的处理器架构,往往编译器不同,环境不同,特别是一些嵌入式系统中的各种程序的编译,于是移植问题也使Makefile文件编写趋于复杂,也显得这个问题很重要.对于这些问题Linu

Configure,Makefile.am, Makefile.in, Makefile文件

一 软件安装关于 makefile文件问题 如果拿到的工程文件中,没有Makefile文件,而只有configure.in和Makefile.am文件,我们是不能够直接进行编译的,必须根据configure.in和Makefile.am文件生成编译所需的Makefile文件.具体操作步骤如下: 1.执行aclocal,产生aclocal.m4文件 aclocal是一个perl 脚本程序,它的定义是:“aclocal - create aclocal.m4 by scanning configur

【转载】Getting Started with Spark (in Python)

Getting Started with Spark (in Python) Benjamin Bengfort Hadoop is the standard tool for distributed computing across really large data sets and is the reason why you see "Big Data" on advertisements as you walk through the airport. It has becom

Heartbeat+DRBD+MySQL高可用方案

Heartbeat+DRBD+MySQL高可用方案 =============================================================================== 概述: =============================================================================== 方案介绍  1.方案介绍及优缺点 ★方案介绍 本方案采用Heartbeat双机热备软件来保证数据库的高稳定性和连续性,数

搭建lamp环境Q&A

Q1:no acceptable C compiler found in $PATH A:yum -y install gcc Q2:红帽没有注册,无法使用yum A:vim /etc/yum.repo.d/XXXX.repo 将第一行的 -$basearch-debug 删除 将第二行的url=后面的内容替换为http://mirrors.163.com/centos/5/os/i386/ enbaled=0换成1 GPG-KEY修改成http://mirrors.163.com/centos

automake简介

在 Unix 上写过程序的人尤其是用 C 来开发程序的人一般都遇到过 Makefile,用 make 来开发和编译程序的确很方便,可是要写出一个 Makefile 就不那么简单了.GNU Make 那份几百页的文件,让许多人害怕.当然,现在关于 make的文档比较多,不过写一个 Makefile 总是一件很烦人的事情,GNU Autoconf 及Automake 这两个软件就是帮助程序开发者轻松产生 Makefile 文件的.现在的 GNU 软件如 Apache, MySQL Minigui 等

zabbix 3.0.3 安装

1:安装nginx 复制 zabbix 包下的 zabbix-3.0.3/frontends/php 到nginx 执行的程序目录 2:安装php php.ini: max_execution_time = 300max_input_time = 300 post_max_size = 16M always_populate_raw_post_data = -1 date.timezone = Asia/Shanghai extension_dir = "/opt/app/php/lib/php