Hi,
I have a PS Script that renames all datastores starts "datastore1*" to " hostname-localds" in vcenter, but even if I add some entries to apply only a cluster, it first shows the host list of cluster I define, but then script applies to all vcenter.
I want to apply to the cluster I defined.
How can I fix this? What am I missing here when I try to update my script?
We need to run the script only for hosts in a cluster for renaming their local datastores from datastore1 to hostname-localds
My Script is as below;
Connect-VIServer vcenter.abc.local
Get-Cluster Clusternamehere | Get-VMHost
$datastoreNames = get-datastore datastore1*
$datastoreNames
foreach ($Datastore in $datastoreNames) {
write-host $Datastore.name "- " -NoNewline
$VMhostFQDN = (get-vmhost -id $(get-datastore $datastore).ExtensionData.host.key).name
$VMhostname = $VMhostFQDN.Split(".")[0]
$datastorenewname = $VMhostname + "-localds"
Get-datastore -name $datastore | Set-datastore -Name $datastorenewname
}