PowerShell Script to list NetApp LUNs Mapped to Igroups

I wanted to get a list of which LUNs on my NetApp filer were mapped to each igroup. This script is not very efficient but it gets the job done in the format I wanted it in.

Using Windows PowerShell with the NetApp Data ONTap Module loaded and already connected to the filer I wanted to report against (using Connect-NaController) fist off I got a list of igroups and saved them into an array, i.e.

$igroups = Get-Naigroup

Then I created an object with the properties I wanted to collect using the following syntax

$output = “” | Select igroup, LUNid, Path

Then for each object in the $igroups array I had collected I ran Get-NaLUNbyigroup for each of the LUN ids 0 through to 255. I used the –ErrorAction:SilentlyContinue common parameter to hide the error messages for the LUN ids not mapped to the igroup. I collected the information I wanted in the $output object and then outputted the contents of this object. The commands looked like

Foreach ($igroup in $igroups) {

for ($lunid=0; $lunid -le 255; $lunid++) {

$output.igroup = $igroup.InitiatorGroupName

$output.LUNid = $lunid

$output.Path = get-nalunbyigroup $igroup.InitiatorGroupName $lunid -ErrorAction:SilentlyContinue

$output

}

}

Advertisements
This entry was posted in NetApp, Powershell. Bookmark the permalink.

One Response to PowerShell Script to list NetApp LUNs Mapped to Igroups

  1. Michael Bietz says:

    Hi, i have optimized your Script. I hope you find it needfull.

    $naluns = Get-NaLun
    $output = “” | Select igroup, LUNid, Path

    Foreach ($nalun in $naluns)
    {
    $lunmap = Get-NaLunMap $nalun
    $output.igroup = $lunmap.InitiatorGroupName
    $output.LUNid = $lunmap.LunId
    $output.Path = $lunmap.Path
    $output
    }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s