Skip to content

Instantly share code, notes, and snippets.

@NamedJason
Last active December 1, 2015 16:03
Show Gist options
  • Save NamedJason/d35f7edd3125d41555ae to your computer and use it in GitHub Desktop.
Save NamedJason/d35f7edd3125d41555ae to your computer and use it in GitHub Desktop.
Renames local datastores on an ESXi host based on the hostname to which the datastore is local.
# Renames local datastores on ESXi hosts to use the hostname plus a specified suffix.
# Usage: Rename-Local.ps1 -cluster <Cluster name> -suffix <Datastore Suffix>
# Website: http://virtuallyjason.blogspot.com/
# Reference: http://virtuallyjason.blogspot.com/2015/12/renaming-esxi-host-local-datastores-by.html
# Original script by VMNick0 at http://www.pcli.me/?p=25
[cmdletbinding(SupportsShouldProcess=$True)]
param(
$cluster = "sac-cluster",
$suffix = "-local"
)
get-cluster $cluster | get-vmhost | % {
$_ | get-datastore | ? {$_.name -match "^datastore1( \(\d+\))?$"} | set-datastore -name "$($_.name.split(".")[0])$suffix"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment