scriptcalcfreespacenetappvolumes
PowerShell: Calculate Free Space on NetApp Volumes
Summary: A script to calculate the free space on NetApp mvolumes using PowerShell.
Date: Around 2014
Refactor: 6 April 2025: Checked links and formatting.
This is a script to calculate the amount of free space on NetApp Volumes (which is nice if you have thin provisioned LUNs).
# Debug mode $debug = 0 if ($debug -eq "1"){Write-Host "DEBUG mode enabled!"; $ErrorActionPreference = "Stop"; Write-Host "On error: $ErrorActionPreference"} # Import DATA ONTAP Module Import-module D:\sjoerd\DataONTAP # Select Filer with default option provided $filer = Read-Host "Please enter the name of the filer you want to query [filer01]" if ($filer -eq ""){$filer = "filer01"} # Getting credentials for NetApp filer while ($filercredentials -eq $null) { Write-Host "Please provide authentication credentials for NetApp filer $filer" $filercredentials = $Host.UI.PromptForCredential("Please enter credentials", "Enter NetApp filer credentials", "root", "") } # Connect to Filer Connect-NaController $Filer -Credential $filercredentials | Out-Null # Create a hash table for clear view of the output $myTable = @() ForEach ($volume in (Get-NaVol)){ $SpaceInfo = "" | Select VolumeName,TotalSize,FreeSpace $SpaceInfo.VolumeName = $volume $totalsize = (Get-NaVol $volume).TotalSize $SpaceInfo.TotalSize = $totalsize / 1073741824 $leftoversize = $totalsize Write-Host "Calculating free space for volume $volume with a total size of $SpaceInfo.TotalSize GB." ForEach ($lun in (Get-NaLun | where {$_.Path -match "/$volume/"})){ if ($debug -eq "1"){Write-Host "Doing $lun now"} $lunsize = (Get-NaLun $lun).TotalSize $leftoversize = $leftoversize - $lunsize if ($debug -eq "1"){Write-Host "$volume with a total size of $totalsize has now $leftoversize space left"} } # Convert the amount of bytes left to gigabytes left and round it up to 2 decimals. $SpaceInfo.FreeSpace = [Math]::Round(($leftoversize / 1073741824),2) $myTable += $SpaceInfo } $myTable
scriptcalcfreespacenetappvolumes.txt · Last modified: by 127.0.0.1