PowerShell – New NetApp LUN

Sometimes you need a LUN quickly.  In cases like these, it’s helpful to be able to use PowerShell instead of NetApp’s GUI.  Fortunately, there is a way (requires downloading the NetApp DataOnTap PowerShell Module ver 3.x, which requires you to create an account and sign in).  The following script will create a Volume and LUN of the same size (NetApp best practice), turn on de-duplication for the volume, make both of them thin provisioned, and map an iGroup to the new LUN.

$naController = "FILER.CONTOSO.COM"
$volName = "ESXi_Vol_4"
$lunName = "ESXi_LUN_4"
$lunSize = "1T"
$iGroup = "ESXi"
$Username = "USERNAME"

Import-Module DataOnTap

Connect-NaController -Name $naController -Credential $Username

New-NaVol -Name $volName -Aggregate aggr1 -Size $lunSize
New-NaLun -Path /vol/$volName/$lunName -Size $lunSize -Unreserved #Create LUN and mark as thin provisioned

$volObj = Get-NaVol $volName

Set-NaVolOption $volObj.Name guarantee none #Thin Provision Volume
Enable-NaSis -path "/vol/$($volObj.name)" #Dedupe Volume

Set-NaLunSpaceReserved -path /vol/$volName/$lunName -off #Thin Provision LUN

Add-NaLunMap /vol/$volName/$lunName $iGroup

Leave a Reply