Software Development Kit (SDK) and API Discussions
Software Development Kit (SDK) and API Discussions
Hi
I am writing a script for volume reporting. Can anyone tell me best way converting bytes to higest possible unit.
and is $vol.SnapshotBlocksReserved return size in blocks? do I have to divide this with 1024 to convert into bytes?
Thanks
Charan
Solved! See The Solution
Use the "ConvertTo-FormattedNumber" cmdlet which ships with the NetApp PowerShell toolkit. This will convert bytes to a human readable number...
PS C:\> ConvertTo-FormattedNumber -Value 1024000 -Type DataSize -NumberFormatString 0 1000 KB PS C:\> ConvertTo-FormattedNumber -Value 10240000 -Type DataSize -NumberFormatString 0 10 MB
PS C:\> ConvertTo-FormattedNumber -Value 10240000 -Type DataSize -NumberFormatString 0.0
9.8 MB PS C:\> ConvertTo-FormattedNumber -Value 102400000 -Type DataSize -NumberFormatString 0 98 MB
Notice that it will round based on the "-NumberFormatString" value.
If the result is in blocks, then each one represents 4096 bytes (4KB). You'll need to multiply by 4096.
Hope that helps.
Andrew
Use the "ConvertTo-FormattedNumber" cmdlet which ships with the NetApp PowerShell toolkit. This will convert bytes to a human readable number...
PS C:\> ConvertTo-FormattedNumber -Value 1024000 -Type DataSize -NumberFormatString 0 1000 KB PS C:\> ConvertTo-FormattedNumber -Value 10240000 -Type DataSize -NumberFormatString 0 10 MB
PS C:\> ConvertTo-FormattedNumber -Value 10240000 -Type DataSize -NumberFormatString 0.0
9.8 MB PS C:\> ConvertTo-FormattedNumber -Value 102400000 -Type DataSize -NumberFormatString 0 98 MB
Notice that it will round based on the "-NumberFormatString" value.
If the result is in blocks, then each one represents 4096 bytes (4KB). You'll need to multiply by 4096.
Hope that helps.
Andrew
Hi Andrew,
Is there any cmdlet to check volume and snapshot used capacity[the value return by "df -h" command's output("Capacity" field)] in percentage?
Thanks,
Charan
It's returned by Get-NcVol in the "VolumeSpaceAttributes" property...
Get-NcVol | Select Name,@{'N' = "PercentageSnapShotReserveUsed"; 'E' = { $_.VolumeSpaceAttributes.PercentageSnapshotReserveUsed }}
Andrew
I think DOT 7 Mode doesn't have that property 😞
7-mode objects don't directly return as much information, but we can still get the data by querying for the oldest snapshot and using it's cumulative total:
Get-NaVol | %{ $data = "" | Select Filesystem,Total,Used,Avail,Capacity $snapReserve = $_.SnapshotBlocksReserved * 1024 $snapUsed = ($_ | Get-NaSnapshot | Sort-Object -Property Created | Select-Object -First 1).CumulativeTotal $data.Filesystem = "/vol/$($_.Name)/.snapshot" $data.Total = ConvertTo-FormattedNumber $snapReserve DataSize $data.Used = ConvertTo-FormattedNumber $snapUsed DataSize $data.Avail = ConvertTo-FormattedNumber ($snapReserve - $snapUsed) DataSize $data.Capacity = ConvertTo-FormattedNumber (($snapUsed / $snapReserve) * 100) Percent $data }
Andrew
Thats really useful Andrew. Below is what I found an alternative way.
((get-naefficiency Vol0).snapusage).Reserve
((get-naefficiency Vol0).snapusage).used
Now need help to create an array of snapshots created dates for a volume. I know Its more powershell related query than Data ONTAP.
Eg: If the Vol0 has 10 snapshots, I want to create a string array of size 10 that each eliment carries one snapshot's created date.
Thanks
Kabir Charan
The DateTime object is somewhat more useful...you can do comparisons and intervals and such much easier...
$snapTimes= (Get-NaSnapshot myvol).AccessTimeDT
Plus you can simply pipe to Out-String to get an actual string if needed...
$snapTimes= (Get-NaSnapshot myvol).AccessTimeDT | Out-String
Hope that helps.
Andrew