Mapping Virtual Machines to Datastores to Storage, Part 2

In a previous post, I walked through the challenges facing one of my customers during a recent outage, during which they needed to understand the mapping of virtual machines to datastores to LUNs.

Due to time constraints, I didn’t have the time to properly test and wrap everything into a nice little package, so the solution I ended up with actually used 2 different scripts… one to collect information on the virtual machines and their datastores, and another to collect information on the SCSI LUNs underlying the datastores.

I wasn’t satisfied, however, and knew I should be able to do it all in one script.  After a bunch of fiddling and testing, I was able to come up with the following:

  • I start by prompting the end user for the name of a target export file.
  • Then I capture information on all the virtual machines for the vCenter in question.
  • Entering a loop, I assign a few variables (more for ease of reference than anything else)
  • Then I capture information on the datastore – and here’s the key – using the name of the datastore as reported by the virtual machine as the filter parameter.
    • Get-View -ViewType datastore -Filter @{“Name”= “^$dsname$”}
  • Then using a Select-Object statement I capture a bunch of properties on the datastore and the virtual machine and
  • Export to a CSV file.

Once I figured out how to use the name of the datastore as reported by the virtual machine as the filter parameter, the rest sort of solved itself.  Here is the completed script:

It should be noted that this hasn’t been tested and probably doesn’t account for virtual machines that have VMDK files across multiple datastores, but then that wasn’t relevant for the customer in question.

I openly admit I am not a programmer, and only a novice PowerShell / PowerCLI scripter, so I am open to comments / suggestions!

Note: this was a script that worked in my environment. There is no warranty or support with this script, please use at your own risk.

Advertisements

About Tom

Just a guy, mostly a father and husband, pretending to be a technologist, constantly underestimating how much there is to learn.... content is mine
This entry was posted in Adventures in Scripting, Automation, From the field, TechInfo, Virtualization - Server and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s