NetApp Community Update
This site will enter Read Only mode on July 23 as we prepare to move to a new platform. You will still be able to view content, but posting and replying will be temporarily disabled.
We're excited to launch our new Community experience on July 30 and more information will follow soon.
Stay connected during the transition - Join our Discord community today.

Microsoft Virtualization Discussions

struggling to get sum of volumes & luns

sakalava
2,287 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
2,275 Views

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

TzwaynY
2,132 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
2,129 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