SHIFT

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

User Tools

Site Tools


scriptcalcfreespacenetappvolumes
Differences

This shows you the differences between two versions of the page.

Link to this comparison view

scriptcalcfreespacenetappvolumes [2013/04/20 09:48] (current)
sjoerd created
Line 1: Line 1:
 += 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).
 +
 +<code powershell>​
 +# 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
 +</​code>​
 +
 +{{tag>​scripts netapp storage}}
scriptcalcfreespacenetappvolumes.txt ยท Last modified: 2013/04/20 09:48 by sjoerd