Monday, May 25, 2015

Mass creation of vDS portgroups using PowerCLI

There’s a potential project going on to migrate off of the Nexus 1000v distributed switch. One of the things that will be needed, is to create portgroups for all the existing Nexus port profiles.

Following is a simple PowerCLI script put together to help with this. It simply creates the port groups from entries in a .csv file. Nothing else is done with respect to the migration.

It’s a practical, functional script. It’s not fully featured or doing anything clever. In essence, it’s what I tend to use Powershell and PowerCLI for, getting tedious things done quickly. It’s missing the “correct” way to do things, but took 10 minutes to put together - which shows.

The core of the script is basically a couple of lines. Fleshed out with some comments, and an initial check on whether a connection has been made to the vCenter before running the script. Typically in my everyday work, I have PowerCLI connections made to the VC’s, so don’t like scripts to nag me to connect. But I’ve added a rudimentary check for this. If already connected, you’ll carry on as normal, if not connected, you’ll be prompted for the VC and the script will disconnect you at the end.

The other assumption here is that all the portgroups are going to be of type VLAN - ie, we’ve got trunked NICs, so each portgroup will need a VLAN ID set.

The script uses a .csv file that you will need to generate - this is my typical approach on these things, as I just find it easy to work with. The layout of the .csv file (ie the column name that you will need) is :

vDS - name of vDS that we want to create the portgroup on
pgName - name of the portgroup to create
NumPorts - number of ports for the portgroup
vlanID - vlanID.

Once it’s created the portgroups, it will just print out the name, number of ports, port binding and vlan configuration for every portgroup on the dVS for confirmation.


# Check if already connected to VC or not. If not, prompt to.
if ($ -eq $null) {
	$vc = Read-Host "Enter the VC to connect to"
	Connect-VIServer $vc

	Write-Host "Now connected to " -ForegroundColor Magenta

	# $wasConnected set to no - this will be used at the end to prompt 
	# whether to disconnect the session.
	$wasConnected = "no"
else {
	# There was already a session connected - display it and continue.
	Write-Host "Currently connected to " -ForegroundColor Magenta

# Read in the .csv file with all the details that we'll need
# Layout (ie, column names) of the .csv is  :
# vDS - name of vDS that we want to create the portgroup on
# pgName - name of the portgroup to create
# NumPorts - number of ports for the portgroup
# vlanID - vlanID - assumption here is we've got a trunk, and each portgroup needs 
# it's own vlan ID to identify the tag
$srcFile = Read-Host "Enter the name of the .csv file to work with"
$vdsPortgroup = Import-Csv $srcFile
foreach ($portgroup in $vdsPortgroup){
	Get-VDSwitch $portgroup.vDS | New-VDPortgroup -name $portgroup.pgName -NumPorts $portgroup.numports -VlanId $portgroup.vlanID

Write-Host "`nPortgroups created. Now confirming settings" -ForegroundColor Cyan

Get-VDSwitch $portgroup.vDS | Get-VDPortgroup | select name, numports, portbinding, vlanconfiguration
# If a connection was needed to the VC at the start of the script, then prompt
# to confirm whether to disconnect the session.
if ($wasConnected -eq "no")
	Disconnect-VIServer $vc -confirm:$true

Sample output :

Currently connected to

Enter the name of the .csv file to work with: dvs-test.csv

Name NumPorts PortBinding
—- ——– ———–
scriptpg1 100 Static
scriptpg2 150 Static
scriptpg3 100 Static
scriptpg4 200 Static
scriptpg5 125 Static

Portgroups created. Now confirming settings

Name : scriptpg1
NumPorts : 100
PortBinding : Static
VlanConfiguration : VLAN 500

Name : scriptpg5
NumPorts : 125
PortBinding : Static
VlanConfiguration : VLAN 504

Name : scriptpg2
NumPorts : 150
PortBinding : Static
VlanConfiguration : VLAN 501

Name : scriptpg4
NumPorts : 200
PortBinding : Static
VlanConfiguration : VLAN 503

Name : scriptpg3
NumPorts : 100
PortBinding : Static
VlanConfiguration : VLAN 502

Name : dvPortGroup
NumPorts : 128
PortBinding : Static
VlanConfiguration :

Name : CloudMgmt-vDS-DVUplinks-888
NumPorts : 2
PortBinding : Static
VlanConfiguration : VLAN Trunk [0-4094]

  1. buy essays

    Monday, February 19, 2018 - 12:35:44

    I like this post. I want to more information about this topic and now, I got all information from your post. Everything defines in this post is awesome. I think you should make more post which helps us.I also share a resource relevant your topic. You can compare with my blog

  2. Do My Essay For Me

    Monday, May 7, 2018 - 12:44:58

    When you make another portgroup, it naturally incorporates the dvUplinks, however for this situation, we needed to evacuate them and utilize the LAG gathering. We likewise physically made the switch and the LAG assemble before running this switch.

  3. gunship battle mod

    Friday, September 21, 2018 - 14:09:25

    Awesome post about also check it Blog!

  4. temple run 2 mod

    Friday, September 21, 2018 - 14:10:17

    Thanks a lot for sharing this useful information.

  5. mobile legends mod

    Friday, September 21, 2018 - 14:11:10

    Thank You For Amazing Information Admin Please Check My Article On

  6. Make My Audit Assignment

    Saturday, October 6, 2018 - 15:32:54

    This Is Really A Great Stuff For Sharing. Keep It Up .Thanks For Sharing.

  7. australia essay writing

    Saturday, October 20, 2018 - 03:30:03

    There is too many information. I can handle that on my own.

  8. Myles

    Wednesday, October 31, 2018 - 15:18:05

    I’ve been browsing online more than 3 hours today, yet I never
    found any interesting article like yours. It is pretty worth enough for me.

    In my view, if all web owners and bloggers made good content as you
    did, the internet will be a lot more useful than ever before.


    Monday, December 17, 2018 - 21:02:19

    It’s genuinely very complex in this active life to listen news on TV, thus I only use world
    wide web for that purpose, and obtain the most recent information.

  10. Dissertation writing services

    Monday, December 31, 2018 - 12:50:36

    I would like to appreciate all your efforts, I have used many other services several times and I am very happy with it too.

  11. Hero Instinct

    Sunday, January 6, 2019 - 13:10:18

    Three are usually cheap Ralph Lauren available for sale each and every time you wish to buy.

  12. Text Chemistry

    Sunday, January 6, 2019 - 14:24:34

    This is also a very good post which I really enjoy reading. It is not everyday that I have the possibility to see something like this.

  13. Relationship Rewrite Method

    Sunday, January 6, 2019 - 14:33:55

    Excellent effort to make this blog more wonderful and attractive.

  14. 13 Zodiac Signs

    Sunday, January 6, 2019 - 14:42:40

    This is really very nice post you shared, i like the post, thanks for sharing..

  15. How To Make Yourself Pee

    Sunday, January 6, 2019 - 16:09:19

    What a really awesome post this is. Truly, one of the best posts I’ve ever witnessed to see in my whole life. Wow, just keep it up.

  16. How To Turn a Guy On

    Sunday, January 6, 2019 - 16:15:37

    Hey, great blog, but I don’t understand how to add your site in my rss reader. Can you Help me please?

  17. How I Work

    Thursday, January 17, 2019 - 16:44:04

    I recently came across your article and have been reading along. I want to express my admiration of your writing skill and ability to make readers read from the beginning to the end. I would like to read newer posts and to share my thoughts with you.

  18. Buy Essay Online

    Monday, February 11, 2019 - 09:45:05

    Do you believe in magic? Let’s try a trick! Ask Buy Online Essay, “Can you write my essay for me” and place an order. Our writers will work behind the scenes to fulfil your fantasy. The result will be revealed to you on your selected date of submission. Order now!

  19. cialis

    Thursday, May 9, 2019 - 05:12:06

    Hmm it appears like your blog ate my first comment (it
    was super long) so I guess I’ll just sum it up what I wrote and say, I’m thoroughly enjoying your
    blog. I as well am an aspiring blog blogger but I’m still new to the whole thing.
    Do you have any suggestions for rookie blog writers?
    I’d certainly appreciate it.

  20. Perez

    Tuesday, June 4, 2019 - 04:39:58 Bottega Veneta Christian Louboutin Heels Ray Ban Sunglasses Christian Louboutin Nike Roshe Adidas Sneakers Fitflop Sale Clearance Jordan Shoes Oakley Standard Issue Fitflop Sandals Clearance Oakley Eyeglasses Oakley Si ECCO Shoes Christian Louboutin Shoes Adidas Outlet Air Max Oakley Sunglasses Ray Ban Wayfarer Sunglasses Cheap Oakley Sunglasses Pandora Goyard Handbags Pandora UK Christian Louboutin Shoes Fitflop Outlet Pandora Bracelet Pandora Jewelry Nike Outlet Adidas Superstar Jordan 11 Low Fitflop Sandals Longchamp Outlet Louboutin UK Bottega Veneta Handbags Pandora Jewelry Pandora Charms Pandora Jewelry Official Site Oakley Prescription Sunglasses Ferragamo Outlet Pandora Pandora Jewelry NMD R1 Pandora Jewelry Pandora Jewelry Official Site Black Friday Oakley Sunglasses Ralph Lauren Balenciaga ECCO Ray Ban Sunglasses Outlet Nike Outlet Store Ray Ban Sunglasses On Sale Moncler Jackets Pandora Charms Adidas NMD Fitflop Sale Clearance Adidas Yeezy Ed Hardy Yeezy Balenciaga Sneakers Ray Ban Eyeglasses Pandora Official Site Birkenstock Sandals On Sale Moncler Outlet Air Max Nike Factory Outlet Christian Louboutin Valentino Outlet Ray Ban Sunglasses Oakley Sunglasses Ray Bans Moncler Outlet Store Yeezy Pandora Ray Ban Aviator Sunglasses Nike Outlet Store Goyard Bags Pandora Charms Jewelry Pandora Charms Canada Red Bottom Shoes Pandora Outlet Birkenstock Outlet Online Cheap Ray Ban Sunglasses Pandora Charms Outlet Moncler Official Site Pandora Bracelet Charms Adidas Yeezy Ray Ban Sunglasses Moncler UK Ferragamo Shoes Nike Outlet Kate Spade Skechers Adidas Yeezy Kate Spade Purses Nike Sneakers Balenciaga Sneakers Jordan 11 Birkenstock Sandals Oakley Outlet Pandora Jewelry Timberland Boots

  21. hero tersakit di mobile legend

    Sunday, January 5, 2020 - 08:48:20

    Thanks very interesting blog!

  22. call of duty mobile hack apk download

    Friday, February 7, 2020 - 01:12:20

    I visited various websites however the audio quality for audio songs current at this web site is in fact fabulous.

  23. fleck 5800 water softener

    Thursday, February 13, 2020 - 08:17:05

    magnificent points altogether, you simply received a new reader.
    What might you suggest in regards to your publish
    that you made a few days in the past? Any positive?

  24. Pure Greens Review

    Tuesday, February 18, 2020 - 12:38:23

    What’s up, its good piece of writing regarding media print, we all be aware of media is a wonderful source of facts.

  25. Man Tea Rock Hard Formula Review

    Tuesday, February 18, 2020 - 12:38:54

    Hey there are using Wordpress for your blog platform? I’m new to the blog world but I’m trying to get started and set up my own. Do you need any coding expertise to make your own blog? Any help would be really appreciated!

  26. BP Optimizer Review

    Tuesday, February 18, 2020 - 12:39:17

    Hello, after reading this awesome article i am too happy to share my knowledge here with mates.

  27. Zenith Labs Zenith Pure Greens Reviews

    Wednesday, February 19, 2020 - 12:05:57

    What’s up to every , as I am really eager of reading this website’s post to be updated daily. It contains fastidious stuff.

  28. Man Tea Rock Hard Formula Supplement

    Wednesday, February 19, 2020 - 12:09:11

    Hello colleagues, how is the whole thing, and what you would like to say on the topic of this piece of writing, in my view its truly amazing for me.

  29. Vision 20 20 protocol Ingredients

    Wednesday, February 19, 2020 - 12:12:21

    Hi, this weekend is good designed for me, because this occasion i am reading this enormous informative article here at my home.

  30. cbd for athletes

    Thursday, February 20, 2020 - 22:53:43

    Good way of telling, and pleasant piece of writing to take information regarding my presentation topic, which i am going to present in college.

  31. <a href="Http://"> Resurge Review</a>

    Monday, March 2, 2020 - 11:35:20

    I do not even know the way I ended up right here, but I thought this put up used to be great. I don’t recognize who you are but certainly you are going to a famous blogger should you aren’t already.

  32. Resurge Review

    Monday, March 2, 2020 - 11:39:32

    Good answer back in return of this issue with firm arguments and describing the whole thing regarding that.

  33. Brain C-13 Review

    Monday, March 2, 2020 - 11:40:37

    I don’t even know how I ended up here, but I thought this post was great. I don’t know who you are but certainly you’re going to a famous blogger if you aren’t already Wink Cheers!

  34. maurten gel canada

    Saturday, March 14, 2020 - 02:17:09

    It’s in reality a great and useful piece of information. I’m happy that you just shared this useful
    info with us. Please keep us informed like this. Thanks for sharing.

  35. skratch labs founder

    Saturday, March 14, 2020 - 08:29:34

    I’m impressed, I have to admit. Seldom do I encounter a blog that’s both equally educative and amusing,
    and without a doubt, you have hit the nail on the head. The
    problem is something that too few people are speaking intelligently about.

    Now i’m very happy I came across this during my search for something concerning this.

  36. yanmaneee

    Sunday, March 15, 2020 - 15:29:52

  37. Useless Web

    Monday, March 16, 2020 - 14:40:42

    Useless Web

  38. <a href="Https://"> Blood Sugar Premier Review</a>

    Tuesday, March 17, 2020 - 13:06:54

    magnificent put up, very informative. I wonder why the opposite specialists of this sector do not understand this. You must proceed your writing. I am sure, you have a huge readers’ base already!

  39. Blood Sugar Premier Review

    Tuesday, March 17, 2020 - 13:07:58

    magnificent put up, very informative. I wonder why the opposite specialists of this sector do not understand this. You must proceed your writing. I am sure, you have a huge readers’ base already!

  40. Blood Sugar Premier Review

    Tuesday, March 17, 2020 - 13:09:23

    magnificent put up, very informative. I wonder why the opposite specialists of this sector do not understand this. You must proceed your writing. I am sure, you have a huge readers’ base already!

  41. Resurge Reviews

    Tuesday, March 17, 2020 - 13:09:55

    Fantastic beat ! I wish to apprentice while you amend your site, how could i subscribe for a blog web site? The account aided me a acceptable deal. I had been tiny bit acquainted of this your broadcast offered bright clear idea

  42. sloth hiking team t shirt

    Sunday, April 19, 2020 - 21:13:15

    It’s impressive that you are getting ideas from this paragraph as well as from our dialogue made
    at this place.

  43. sloth hiking team t shirt

    Monday, April 20, 2020 - 00:54:47

    Right away I am going to do my breakfast, when having my breakfast
    coming over again to read more news.

  44. asena

    Sunday, May 24, 2020 - 00:07:31

Add comment

Fill out the form below to add your own comments