• RSS
  • Twitter
19
July
Comments

Scenario: Here we are again – crunch time.  I have a request that is Jalapeno hot, and it requires ~100 new datastores, ~1000 virtual disks, and for some unknown reason a RDM or two sprinkled in.  At the end of the day this is really no problem at all for two reasons:

  1. PowerCLI is an extremely viable product that allows us to automate pretty much whatever task we want to for vCenter.
  2. The most important reason, feel free to quote me on this: Clicking buttons is dumb! Especially when we are talking about this kind of volume.

If your deployment is somewhat standard, meaning, 1:1 (LUN:Datastore) and many virtual disks to datastore then you are in luck.  We can do this in record time, with small effort, and look like a top gun while doing it.  Señor Cruise will be proud.

Now what?: We start by capturing data, lots of data, and storing them into separate CSV files.  The data that we’ll capture is nothing more than our requirements that we should already have and sorted per step that we have to do.

The first bit of information to capture is the hostname and lun name that we want to add as datastores.  There are only really to items that we need to capture and that is the LunName and HostName of the VMhost has visibility to the LUN, incase you are using iSCSI initiator groups or CHAP security.  If more than one host, in a cluster for example, needs accessibility to the datastore, no problem, just choose one host in that cluster and vCenter will help take care of the rest.

At this point you will want to crack open Excel or your spreadsheet editor of choice.  Use the below as your template.  The headers are important so be sure not to change them. Obviously, the actual HostName as it appears in vCenter or with Get-VMHost and LunName will have to modified to whatever it is in your environment.

HostName LunName
server01 mylun.app.01
server01 mylun.app.02
server01 mylun.app.03
server01 mylun.app.04
server33 mylun.mysqldb.01
server33 mylun.mysqllogs.01
server60 mylun.vms.01
server60 mylun.vms.02

Due to the fact that MSFT Powershell has no hard coded limitations of $Array size your CSV can be as many elements as you like.  Having said that once you have completing drafting your CSV file you should place it somewhere we can call it from.  In this example my CSV file will be stored in C:\CSV\luns.csv.  Once this is completed now the real fun begins.

Let’s Get To Work!:  As you note the below code you will see that our steps are simple as we do the following:

  1. Import our luns.csv to $List.
  2. Create a For Each loop with our instructions.
  3. Do variable transformation on lines 3 & 4.
  4. Create a list of LUNs, which will have the appropriate attributes.
  5. Search that list to match the UID with the LUN name we specified in our CSV.
  6. Store the canonical name of our previous step into a variable.
  7. Create our new datastore as VMFS.
  8. Take a break so the other hosts can add the VMFS volume.
    • I like 180 seconds.  It really depends on how many hosts may be accessing this datastore.  There is no good number to give so feel free to adjust it to your environment.

Closing Thoughts:  This makes simple work out of what can be a tedious task.  Over the course of the next few entries we’ll explore how to automate creating all of those virtual disks, RDM’s, and maybe even get into how to bring the disks online and format them inside of Windows with PowerCLI.

About the author

@VirtualizedCJ CJ is a virtualization professional that loves automation -- maybe a little to much.

Categories: Scripts, Storage

Leave a Reply