Renaming ESXi Host Local Datastores by PowerCLI

One of my customers set up a large number of ESXi hosts, installed on local storage.  Since they're not doing anything with that storage, they never bothered renaming those datastores and so their vCenter inventory was filled with instances of "datastore1 (#)".  This is just a housekeeping thing, but that's really messy.  Generally speaking, a bit of mess isn't a big deal, but those little messes always seem to cause problems when you're troubleshooting some other major issue.  And, fortunately, this is really easy to fix.  Rather than write my own script, I did some quick googling and found that VMNICK had done all the work already, with his own "rename local host storage" script.

In his post, he notes that the script might explode if you use the string "datastore1" on any other datastores in the environment.  Excepting a very particular subset of situations, I'm not a fan of explosions, and so I figured that I could probably fix that issue.  I took the logic of his script and rewrote it a bit, so that it's more particular in its "datastore1" match and so that it performs fewer vcenter queries.  The modified regular expression is as specific as I could think to make it; it'll only match on datastores that are called either "datastore1" or "datastore1 (#)".  If there's any preceding or following text, the regular expression will not match and so this should be more precise in discovering its rename targets.

I also parameterized the meaningful variables and added -WhatIf support; even after you've read and fully understood the (admittedly short and simple) script, I highly recommend using -WhatIf to ensure that it's only targeted datastores that you wish to rename.

Anyway, here's my modified version:

Comments

Popular posts from this blog

Clone a Standard vSwitch from one ESXi Host to Another

PowerShell Sorting by Multiple Columns

Deleting Orphaned (AKA Zombie) VMDK Files