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.

Software Development Kit (SDK) and API Discussions

script to addup volume used and available size

sakalava
2,364 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 ? 

1 ACCEPTED SOLUTION

sakalava
2,231 Views

thanks a lot 

 I think I found an alternative 

 

Get-NcVol | ForEach-Object {
$x = "" | Select Name,Total_TB,Available_TB
$x.Name = $_.Name
$x.Total_TB = [Math]::Round($_.TotalSize / 1TB, 2)
$x.Available_TB = [Math]::Round($_.Available / 1TB, 2)
$x | Format-Table -AutoSize | Out-String | ForEach-Object { $_.Trim("`r","`n") }

View solution in original post

2 REPLIES 2

JohnChampion
2,299 Views

Perhaps convert everything to bytes first then total and convert back to whichever unit you want?

 

function Convert-UnitsToBytes {
    [cmdletbinding()]
    param (
        [Parameter(Mandatory = $True)]
        [uint64]$Size,
        [Parameter(Mandatory = $True)]
	    [ValidateSet('MB', 'GB', 'TB')]$Unit
    )

    # Converts BYTES to a specified UNIT (MB|GB|TB)
    #   - Any other Unit will return the original value passed in

    $Unit = $Unit.ToUpper()

    switch ($Unit) {
        'MB' {
            $bytes = $size * 1MB
        }
        'GB' {
            $bytes = $size * 1GB
        }
        'TB' {
            $bytes = $size * 1TB
        }
        Default {
            $bytes = $size
        }
    }

    return $bytes

}

sakalava
2,232 Views

thanks a lot 

 I think I found an alternative 

 

Get-NcVol | ForEach-Object {
$x = "" | Select Name,Total_TB,Available_TB
$x.Name = $_.Name
$x.Total_TB = [Math]::Round($_.TotalSize / 1TB, 2)
$x.Available_TB = [Math]::Round($_.Available / 1TB, 2)
$x | Format-Table -AutoSize | Out-String | ForEach-Object { $_.Trim("`r","`n") }

Public