Script to Report ESXi Path Status to a SAN
Hey everyone - one of my customers was doing some maintenance on the FC switches recently and wanted an easy way to ensure that all of their ESXi hosts had 4 Active links to their datastores before bringing a switch down for maintenance. Sure, we can click through the GUI and manually examine each host... or we can automat it!
So, I wrote a script to report the status of all paths to a given datastore (or datastores via wildcard matching) for all hosts that are connected to it! The usage on this guy is pretty straight-forward: .\report-datastorePaths.ps1 -datastoreName <name of datastore to examine; multiple datastores may be specified with wildcards> -alertThreshold <if the number of active paths is less than this number, alert the user>
That -alertTreshold parameter (which defaults to 4) is used to cause the script to write to the host if it ever finds a host with fewer than that number Active links. So, if it doesn't spit out any red text, you're probably good to go... but should still examine the table that it generates to make sure that there's nothing unexpected in the "paths" column that might've tripped it up. This worked for me in my environment, but there's a lot of variability out there, so test thoroughly before trusting its results and always make sure that you understand what internet-code is gonna do before you execute it!
Speaking of "internet code" there are effectively four lines that are really meaningful in this script (the rest just gets the objects that need to be examined or manage output or handle errors):
$naaID = $Datastore.extensiondata.info.vmfs.extent.diskname
$arguments = $esxcli.storage.core.path.list.createArgs()
$arguments.device = $naaID
$paths = ($esxcli.storage.core.path.list.invoke($arguments)).state
You can probably guess, but $Datastore is then result of a get-Datastore and $esxcli is the result of get-esxCLI -v2. These lines are just figuring out the naa ID of the datastore that we want to look at, then invoking esxcli storage core path list -d <that naa id> to display the paths to that storage device. Since that $esxcli is inherently tied to a given ESXi host, it's going to show us the paths to that device from that host. So, I just baked all of that into a pair of foreach loops to give me every host's perspective on every datastore, and voila!
Comments
Post a Comment
Sorry guys, I've been getting a lot of spam recently, so I've had to turn on comment moderation. I'll do my best to moderate them swiftly after they're submitted,