This is a quick blog post to rename multiple datastore to Hostname-local using the residing cluster . Use case could be after auto deploy from stateless to stateful.
$cred = Get-Credential
$vCenters = "lab-vcenter01.lab.local", "lab-vcenter02.lab.local"
Connect-VIServer $vCenters -Credential $cred
### Script 1
[cmdletbinding(SupportsShouldProcess=$True)]
param(
$cluster = "PRE_PROD-Cluster","PROD-Cluster",
$suffix = "-local"
)
get-cluster $cluster | get-vmhost | % {
$_ | get-datastore | ? {$_.name -match "^datastore1( \(\d+\))?$"} | set-datastore -name "$($_.name.split(".")[0])$suffix"
}
### One liner lovers like myself
Get-Datastore -Name datastore1* | %{ $n = '' + (Get-VMHost -Id $_.ExtensionData.Host[0].Key[0]).Name.Split('.')[0] + '-local';Set-Datastore -Datastore $_ -Name $n }
get-datastore | ?{$_.Name -like "*local*"} | ft -a
$cred = Get-Credential
$vCenters = "lab-vcenter01.lab.local", "lab-vcenter02.lab.local"
Connect-VIServer $vCenters -Credential $cred
### Script 1
[cmdletbinding(SupportsShouldProcess=$True)]
param(
$cluster = "PRE_PROD-Cluster","PROD-Cluster",
$suffix = "-local"
)
get-cluster $cluster | get-vmhost | % {
$_ | get-datastore | ? {$_.name -match "^datastore1( \(\d+\))?$"} | set-datastore -name "$($_.name.split(".")[0])$suffix"
}
### One liner lovers like myself
Get-Datastore -Name datastore1* | %{ $n = '' + (Get-VMHost -Id $_.ExtensionData.Host[0].Key[0]).Name.Split('.')[0] + '-local';Set-Datastore -Datastore $_ -Name $n }
get-datastore | ?{$_.Name -like "*local*"} | ft -a
Can you add this to auto deploy as part of the initial host profile attachment? If so would you be kind enough to cover this in a blog? Thanks for sharing these useful tips.
Thanks. I will try and cover this in my next post