Hi All,
Currently we are running below PowerShell command using Get-Datastore cmdlet from automation tool. The query is giving the lun available in the cluster. But we need to modify the same script to retrun lun without donotuse in its name.
New-VIProperty -Name availableMB -ObjectType Datastore -Value {$ds = $args[0]; $sum = 0; if ($ds.ExtensionData.summary.uncommitted -gt 0) { $sum = $ds.ExtensionData.summary.uncommitted}; $sum = $ds.ExtensionData.summary.freeSpace - $sum; $sum = $sum/1024/1024; return $sum} -Force
(Get-Cluster -Name ${vCenterCluster} | Get-VMhost) | Where-Object {$_.availableMB -ge (${diskSize}*1024+${reservedSpace}*$_.CapacityMB) -and $_.CapacityMB -ge (${lunSize}*1024) -and $_.Name -like "*_lun*"} | Sort-Object availableMB | Select -First 1
Please provide your inputs.
For Example: If there is lun named xxxx_lun01donotuse or donotusexxxx_lun01 we dont want this lun to be returned from the script.
Thanks and Regards
Riyas Hussain A
As far as I can tell you are not feeding datastore objects to the Where-clause, so you can not test on datastore properties in that Where-clause.
You can feed the objects produced by Get-Datastore to the Where-clause (see my previous reply)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Isn't there something missing in your script ?
You use the availableMB property in the Where-clause, but that property is defined on a datastore object, not on a VMHost object.
And what are these ${...} notations ?
Are these parameters you pass to the script ?
That aside, I guess that with the "lun name", you mean the datastore name ?
If that is the case, then you can use a Where clause to test on the name.
Something like this for example:
Get-Cluster -Name MyCluster | Get-Datastore | Where {$_.Name -notmatch "donotuse"}
The -match operator expects a RegEx expression, so in this case we are skipping any datastore that has "donotuse" in it's name.
Does that answer your question ?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Yes. ${} are the variables which we pass input. I am mentioning Datastore only. As per your comments is the below script correct to provide the expected value?
Please confirm.
(Get-Cluster -Name ${vCenterCluster} | Get-VMhost) | Where-Object {$_.availableMB -ge (${diskSize}*1024+${reservedSpace}*$_.CapacityMB) -and $_.CapacityMB -ge (${lunSize}*1024) -and $_.Name -like "*_lun*" -and $_.Name -notmatch "donotuse"} | Sort-Object availableMB | Select -First 1
Thanks and Regards
Riyas
As far as I can tell you are not feeding datastore objects to the Where-clause, so you can not test on datastore properties in that Where-clause.
You can feed the objects produced by Get-Datastore to the Where-clause (see my previous reply)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference