My name is Josh Atwell and I've been working in the IT industry exclusively since 2004. I'm a serial IT community builder and leader, podcaster on vBrownBag and VUPaaS podcasts, vExpert, CiscoChampion, author, and generally fun person to have around. I am currently working as a Cloud Architect for SolidFire.

vTesseract is my personal presence for my thoughts, musings, and technical write-ups involving PowerShell, datacenter virtualization and other technologies I come across daily. The opinions and thoughts on this site are my own and are not endorsed or affiliated by my employer or anyone else. This is done on my own free time and all work is limited based on my time and available resources. Your comments, thoughts, opinions are welcome. Thanks for reading!

Current Resume-CV

Fri Nov 18 on the Range

One of my favorite uses of #PowerShell and #PowerCLI is for implementation.  I’m an engineer at heart so building things is always rewarding.  However, getting something to build things for you is inspiring.  If you ever followed my old blog I had built a script for creating a standard switch network in a VMware environment based on data in a .CSV file.

Old Blog Site here —> http://day2dayadmin.blogspot.com/2009/10/configuring-network-with-powercli-and.html

The Problem

Enough of the past. Now to my point.  I was recently pinged about a need to generate an incremented list of IP addresses that could be used to set vMotion IP addresses incrementally on the fly.  I typically point requests like this to my link listed above since Excel is amazingly quick and the .CSV in a Excel worksheet gives you the ability to pre-configure and change very easily. This however didn’t specifically meet the request.

The Tool

The first thing came to mind was the fantastic little range operator.  This little guy can save you a ton of time and code but beware because he only works with integers.

From get-help about_operators

The Possible Solution

In the example below I have set my IP sub-address aligned with my subnet as a string.  I then set a variable with the preferred start and stop for the last octet as the range.  Again, this works because they are integers.  In this case I want my IP addresses to increment from to

$IpSubAddress = "192.168.0."
$range = 200..205
$all = @()

foreach($IP in $range){
$IPFull = $IpSubAddress + $IP

#$IPFull = -join($IpSubAddress,$IP)
# Specific logic for required IP address can go here
#For example:
#New-VMHostNetworkAdapter -VMHost  -PortGroup ` 
#-VirtualSwitch  -IP $IPFull -SubnetMask`
#-VMotionEnabled: $true

$all += $IPFull

The Result

As you see below, the populated array $all contains the incremented IP addresses.  You will note that I included a commented out line that could be used towards provisioning a new vMotion network adapter with additional information provided.  I also threw in another option for joining the IP sub-address and the final octet.  That was just for sheer fun and both work just fine.

The Conclusion

Like most things that involve scripting and programming there are multiple ways to accomplish your goals.  Hopefully in this post you were able to see how you can both dynamically and preplan a scripted deployment of standard virtual switching in a VMware environment.

blog comments powered by Disqus