Lots & Lots-o-LUNS

I was doing some work on my NetApp SnapManager 8.0 for SharePoint lab environment today and needed to create a bunch of LUNs for some testing. I put together this short PowerShell script to create 500 LUNs (for fun!). As you can also see even though I provisioned these through the Data ONTAP PowerShell Toolkit 3.0 they all show up in SnapDrive 7.0 for Windows without having to use Connect Disk.

 

SnapDrive 7.0 for Windows sees all the newly created LUNs with a simple Refresh.

 

Param(

  $NumOfLUNS = 0

, $LunPath = '/vol/volSQLTempDb/DataONTAP'

, $LunSize = 1gb

, $Controller = '192.168.0.111'

, $SVM = 'SMSP_SVM'

)

Begin

{

    if ((Get-Module|select -exp name) -notcontains 'DataONTAP'){

        Import-Module DataONTAP

    }

 

    # Connect to the Clustered Data ONTAP system.

    Connect-NcController $Controller -Credential(Get-Credential) -HTTPS -EA Stop | Out-Null

}

Process

{

    do {

        # Create a new LUN.

        $lun = New-NcLun -Path $LunPath$NumOfLUNS -Type windows_2008 -Unreserved -Size $LunSize -VserverContext $SVM

 

        # Get the iSCSI IQN for the host.

        $iqn = Get-NaHostIscsiAdapter| Select-Object -ExpandProperty Iqn

 

        # Find the IGroup for the host.

        New-NcIgroup -Name $iqn -Protocol iscsi -Type windows -VserverContext $SVM

        $IGroup = Get-NcIgroup -VserverContext $SVM | Where-Object {($_.Initiators|Select -Expand InitiatorName) -contains $iqn}

 

        # Map the new LUN to the host.

        Add-NcLunMap -Path $lun.Path -InitiatorGroup $IGroup.InitiatorGroupName | Out-Null

 

        # Rescan drives on the host.

        Start-NaHostDiskRescan

 

        # Create new disk and format.

        Get-NaHostDisk -DataOntap -Uninitialized | New-NaHostVolume

    } while ($NumOfLUNS -le 500)

}

 

The script works (creates LUNs, formats, etc.) but there is one problem, can you find it?

 

P.S. I've been in this do { y } while ( x not something ) retro scripting style for the last few weeks. I promise I'll be out of that mood soon :-)

 

L8R,

Barkz