VMware Cloud Community
riyas1988
Enthusiast
Enthusiast
Jump to solution

Issue with Conversion of TB to GB for powercli

Hi All,

We are running below powershell script on vcenter to get the lun with specified space (2TB). But it is not returning any values even though 2TB lun is available for the cluster. Highlighted RED are the variables we are passing.

(Get-Cluster -Name Cluster name | Get-VMhost) | Where-Object {$_.availableMB -ge (100*1024+0.01*$_.CapacityMB) -and $_.CapacityMB -eq (2048*1024) -and $_.Name -like "*_lun*"} | Sort-Object availableMB | Select -First 1

But when we are giving 273 instead of 2048, the script is returning the lun name.

Please guide what is exact value for 2TB lun size which should be passed here. Is it 2048 or different value?

Thanks and Regards

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
riyas1988
Enthusiast
Enthusiast
Jump to solution

Hi All,

The issue is resolved. I changed 2048 to 2000 and $_.CapacityMB -eq (2000*1024) to $_.CapacityMB -ge (2000*1024) which is returning the 2TB luns.

Thanks for all your suggestions and help.

Regards

Riyas Hussain A

View solution in original post

0 Kudos
5 Replies
MKguy
Virtuoso
Virtuoso
Jump to solution

You're querying $_.availableMB and $_.CapacityMB from a VMHost object there, which does not have these properties. You need a Datastore object, so insert a Get-Datastore into the first block:

(Get-Cluster -Name Cluster name | Get-VMhost | Get-Datastore)

Also there is no "AvailableMB" property for datastore objects. You have FreeSpaceGB/FreeSpaceMB if free space is what you're looking for.

-- http://alpacapowered.wordpress.com
0 Kudos
dmilov
VMware Employee
VMware Employee
Jump to solution

Hi, your script is not correct because you are filtering on VMHost objects that

1. doesn't have  availableMB property

2. The VMHost object doesn't have properties for the luns size.

In order to get LUNs with space more than 2 TB you can use the Get-ScsiLun cmdlet. Here is an example:

Get-Cluster 'Cluster name' | Get-VMhost | Get-ScsiLun | Where-Object { $_.CapacityGB/1MB -ge 2}

Regards,

Dimitar Milov

0 Kudos
riyas1988
Enthusiast
Enthusiast
Jump to solution

Hi,

This is the below script we are running.

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

Correct me if this is wrong.

Regards

Riyas Hussain A

0 Kudos
riyas1988
Enthusiast
Enthusiast
Jump to solution

Hi All,

Below is the complete script.

 

script=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

$GetDatastore=Get-Datastore -VMHost (Get-Cluster -Name Cluster Name | Get-VMhost) | Where-Object {$_.availableMB -ge (30*1024+0.01*$_.CapacityMB) -and $_.CapacityMB -eq (2047.852*1024) -and $_.Name -like "*_lun*"} | Sort-Object availableMB | Select -First 1

$GetDatastore

Regards

Riyas

0 Kudos
riyas1988
Enthusiast
Enthusiast
Jump to solution

Hi All,

The issue is resolved. I changed 2048 to 2000 and $_.CapacityMB -eq (2000*1024) to $_.CapacityMB -ge (2000*1024) which is returning the 2TB luns.

Thanks for all your suggestions and help.

Regards

Riyas Hussain A

0 Kudos