Hello,
our datastore have a naming convention and i want to filter out only the local and backup stores.
Local Stores start with "A_"
Backup Stores with "C_"
We do have different cluster setups ones with 3 and another with more than 4 or 5 Datastores. So i wanted to set my action depending on how many datastores are in the cluster.
here is what i tried so far. and YES i am not a powercli pro at all (mea culpa
Count and comapre
$countlocaldatastore = (Get-Cluster -Name $cluster | Get-Datastore A*).count
$countnfsdatastore = (Get-Cluster -Name $cluster | Get-Datastore C*).count
$countalldatastores = $countlocaldatastore + $countnfsdatastore
if ($countalldatastores -gt 3) {echo "more than 3"}
if ($countalldatastores -le 3) {echo "less or equal than 3"}
This works do far but something dynamic would be much cooler and of course more flexible.
Found this later:
Get-Datastore -RelatedObject $cluster | where {$_.Name -notmatch "B_|D_"}
used it to sort the for freespace:
$mostfreespace = Get-Datastore -RelatedObject $cluster | where {$_.Name -match "A_|C_"} | Sort-Object -Property FreespaceGB -Descending:$true | Select-Object -First 1
$mostfreespace1 = Get-Datastore -RelatedObject $cluster | where {$_.Name -notmatch "B_|D_"} | Sort-Object -Property FreespaceGB -Descending:$true | Select-Object -First 1
$mostfreespace2 = Get-Datastore -RelatedObject $cluster | where {$_.Name -notmatch "B_|D_"} | Sort-Object -Property FreespaceGB -Descending:$true | Select-Object -First 2 | Select-Object -Skip 1
$mostfreespace3 = Get-Datastore -RelatedObject $cluster | where {$_.Name -notmatch "B_|D_"} | Sort-Object -Property FreespaceGB -Descending:$true | Select-Object -First 3 | Select-Object -Skip 2
i need at least 2 stores better 3. As the backup stores usually have more space compared to the local ones i wanted to start with them but if they are not availalble (different cluster) i would like to use the locals.
So the plan is to list all datastores of a cluster but exclude the ones using B_ and D_ in their names.
So far i was not able to get this right. Best would really be all in one which i could later sort for freespace and take the ones with the most first.
Hope you can follow me :smileyhappy:
thank you very much
armin