Microsoft Virtualization Discussions

Is there a better way query volume total space in powershell?

TONY_UNGER
11,784 Views

My boss wanted information about the total capacity of each of our volumes(So including snapshot reserve) along with used space and available. I was going to use get-navol but i noticed this only gives the usable space of the volume not the true total. So i hacked together this script using both get-navol and get-navolsize cmd-let to get what i needed. This is my second script i have ever wrote in PowerShell so i am sure i did a several things wrong but i was able to get the results i wanted. It just seems like it should have been less work and a better way of doing this.

VolumeName,VolumeAvailableSpace,VolumeUsedSpace,VolumeTotalsize

param([string]$paNetAppHost, [string]$pausername)

Import-module DataOnTap

$PathtoCSV = "C:\NetappTotalVolume.csv"

#Connect to filer

Connect-NAController $paNetAppHost–cred $pausername

$allvolumesnames = get-navol | Select-Object Name,Available

#set headers of CSV file

"VolumeName,Available Space(GB),Used Space(GB),Total Volume Space(GB)" > $PathtoCSV

foreach ($netapp_vol in $allvolumesnames) {

$CurrentVolname = $netapp_vol.name

$VolumesAvailable = $netapp_vol.available

$VolumeSizeTotal = get-navolsize -name $CurrentVolname | Select-Object -ExpandProperty VolumeSize

#Convert to GB

$VolumeAvailable1GB = ($VolumesAvailable / 1GB)

$VolumeSizeTotal1GB = ($VolumeSizeTotal / 1GB)

#Calc usedspace

$VolumeUsedSpace1GB = $VolumeSizeTotal1GB - $VolumeAvailable1GB

#Create/add to CSV file

$Combine = $CurrentVolname,$VolumeAvailable1GB,$VolumeUsedSpace1GB,$VolumeSizeTotal1GB

$Combine -join "," >> $PathtoCSV

    }

1 ACCEPTED SOLUTION

vinith
11,636 Views

Hi Tony,

Can you try running this command and check if it serves your purpose? Just Copy Paste the entire snippet below to your powershell console.

Get-NaVol | Select @{Name="VolumeName";Expression={$_.name}},@{Name="TotalSize(GB)";Expression={[math]::Round([decimal]$_.SizeTotal/1gb,2)}}`

,@{Name="AvailableSize(GB)";Expression={[math]::Round([decimal]$_.SizeAvailable/1gb,2)}}`

,@{Name="UsedSize(GB)";Expression={[math]::Round([decimal]$_.SizeUsed/1gb,2)}}`

,@{Name="SnapshotBlocksReserved(GB)";Expression={[math]::Round([decimal]$_.SnapshotBlocksReserved/1gb,2)}}`

,SnapshotPercentReserved

You can also affix an | Export-CSV to this cnippet to export it to a csv file.

View solution in original post

6 REPLIES 6

vinith
11,637 Views

Hi Tony,

Can you try running this command and check if it serves your purpose? Just Copy Paste the entire snippet below to your powershell console.

Get-NaVol | Select @{Name="VolumeName";Expression={$_.name}},@{Name="TotalSize(GB)";Expression={[math]::Round([decimal]$_.SizeTotal/1gb,2)}}`

,@{Name="AvailableSize(GB)";Expression={[math]::Round([decimal]$_.SizeAvailable/1gb,2)}}`

,@{Name="UsedSize(GB)";Expression={[math]::Round([decimal]$_.SizeUsed/1gb,2)}}`

,@{Name="SnapshotBlocksReserved(GB)";Expression={[math]::Round([decimal]$_.SnapshotBlocksReserved/1gb,2)}}`

,SnapshotPercentReserved

You can also affix an | Export-CSV to this cnippet to export it to a csv file.

TONY_UNGER
11,636 Views

It looks like i can take SnapshotPercentReserved and use that to calculate what I was looking for without having to use get-navolsize

Thank you

TONY_UNGER
11,636 Views

To get the value i wanted without using get-navolsize i added this to my script

$VolumeSizeTotal = [math]::Round([decimal]((($netapp_vol.snapshotpercentreserved * 100) * $netapp_vol.TotalSize) + $netapp_vol.TotalSize)/1gb,2)

ill have to start using hashtables on my next script

Carol
11,494 Views

Is there a way to get the value for Snapshot copies space used?

CASTROJSEC
11,477 Views

show-nahelp

 

When the explorer pops up select the cmdlets at the top of the page.  There are a few commands for getting detailed snapshot information. Get-nasnapshotvolumespace  may be the one you are looking for.

Carol
11,468 Views

This gives me the total snapshot space available, I need to get the snapshot space used ?

Public