By default, new ESXi creates a datastore on the local disk called "datastore1" on all new hosts.
When you add a batch of new hosts to vCenter, it will create duplicate names by appending a sequence number as below:
datastore1 datastore1 (1) datastore1 (2) datastore1 (3)
datastore2 datastore2 (1) datastore2 (2) datastore2 (3)
datastore3 datastore3 (1) datastore3 (2) datastore3 (3)
datastore4 datastore4 (1) datastore4 (2) datastore4 (3)
I would like to create powercli script that renames these datastores per new host to format ( short hostname + local + N )
example: esx-local1, esx-local2, esx-local3, esx-local4
Here's my initial function that i suppose to call within the script. There is a CSV file of hostlist that being called.
Function Rename-datastore {
Foreach ($Item in $CSV) {
$ESXHost=$Item.Hostname + ".domain.com"
$ds = get-vmhost $ESXHost | Get-Datastore -name datastore* | sort
Foreach ($datastore in $ds) {
$id = 0
$id+=1
Set-Datastore -Datastore $datastore -name (Get-VMHost $ESXHost -Id $_.ExtensionData.Host[0].Key[0]).Name.Split('.')[0] + '-local'+$id
}
}
}
Thanks in advance. =)