Microsoft Virtualization Discussions

struggling to get sum of volumes & luns

sakalava
1,328 Views

Hello All, 

 

I am attempting to create a script which will add up the total available and used size of all volume 

here is my script 

$vols = Get-NcVol
$voltotal = $vols | Measure-Object -Property TotalSize -Sum
$voltotalsize = ConvertTo-FormattedNumber $voltotal.sum DataSize -Verbose
$volused = $vols | Measure-Object -Property Used -Sum
$volusedsize = ConvertTo-FormattedNumber $volused.sum DataSize -Verbose

 

It is giving me wrong numbers I think this is because the get-ncvol give  volume size in Gb,Tb and Mb so we basically can not add apple to orange 

Has anyone everdone that ? can you give me an exemple ? 

 

3 REPLIES 3

sakalava
1,316 Views

>Please ignore my post I did put it in the wrong forum category 

TzwaynY
1,173 Views

Hi there,

even tho, you want this topic to be closed, I can give you (hopefully) the answer you want.

For the Ontap Tools it does not matter if the size of the luns/volumes are in TB,GB, Gib, Mib or anything. You always get the "raw" bits and bytes as output from the Cmdlet.

 

I think, you want something like this?

$VolTotalSize = $null
$VolUsedSize = $null
$GetNcVols = Get-NcVol
foreach($Vol in $GetNcVols){
    $VolTotalSize = $VolTotalSize + $Vol.TotalSize
    $VolUsedSize = $VolUsedSize + $Vol.Used
}
    Write-Host "Used-Capacity: $VolUsedSize`nTotal-Capacity: $VolTotalSize`nFree-Capacity $(($VolTotalSize - $VolUsedSize) / 1048576)"

I think? That is what you want. If you have any questions, feel free to ask, if anything is unclear (or if I understood it wrong :D)
 
Best regards
Kai
 
 

 

TzwaynY
1,170 Views
Quick Edit: There you also have to divide the variables by 1048576.
Write-Host "Used-Capacity: $VolUsedSize`nTotal-Capacity: $VolTotalSize`nFree-Capacity $(($VolTotalSize - $VolUsedSize) / 1048576)"
 
So like that:
 
  Write-Host "Used-Capacity: $($VolUsedSize /1048576 )`nTotal-Capacity: $($VolTotalSize / 1048576)`nFree-Capacity $(($VolTotalSize - $VolUsedSize) / 1048576)"
 
Note: This will give you the excact MB-Rate of the Volumes. After this, you can divide it further with the "normal" powershell dividing.
Best regards
Kai
Public