SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Sidebar

Recently Changed Pages:

View All Pages


View All Tags


LinkedIn




WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.


Pages with comments

View All Comments

scriptcalcfreespacenetappvolumes

Script: PowerShell: Calculate Free Space on NetApp Volumes

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
You could leave a comment if you were logged in.
scriptcalcfreespacenetappvolumes.txt · Last modified: 2021/09/24 00:25 (external edit)