Community

Subscribe
Highlighted

Lun information the way I want it...

Mad props to Glenn Sizemore for the foundation....

This will give me the output i want to see when i'm looking for igroups and lun mappings.   The important thing here is whether or not your initiator is logged in or not.  That was key for us..  FYI - you can feed a txt file full for filers if you want.

Please comment and let me know if we can improve on this.

#### Code#####

$hosts = @("filer1","filer2")

$hosts | % {           

   Write-Host "`n`tConnecting to Filer: $_"

   $filer = $_ 

   Write-Host "`t-------------------------------------------------------"        

   $c  = Connect-NaController $_           

   $igroups = Get-NaIgroup           

   $LunInfo = Get-NaLun -Terse | Get-NaLunMap | Group-Object Name           

   foreach ($igroup in $igroups) {           

       Write-Host "`n`tigroup Name: " $Igroup.Name           

       Write-Host "`t`tOS_Type: " $Igroup.type           

       Write-Host "`t`tProtocol: "   $Igroup.protocol      

            $initiators = $igroup.initiators | Select -expandproperty 'initiatorname'

             $initiators | % {

               $name = $_

               if ($name -ne $null) {

                        if ((Confirm-NaLunInitiatorLoggedIn -Initiator $name) -eq $false) {

                Write-Host "`t`t`tInitiator Not logged in: " $name

                    }

                        else

                    {

                        Write-Host "`t`t`tInitiator Logged in: " $name

                    }

                            }

                Else

                    {

                        Write-Host "`t`t`tNo initiators assigned to Igroup"

                    }

                }

      # Write-Host "`t`tinitiators: " $(($igroup.initiators|Select-Object -ExpandProperty InitiatorName) -join " ")           

       Write-Host "`t`tLuns  --------------------------------------------------" #"# LUN ID   LUN Path"   

       foreach ($lun in ($LunInfo| where {$_.Name -eq $igroup.Name} | select -ExpandProperty Group)) {

       

          Write-Host "`t`t`tLUN:" $lun.lunID ":" $lun.path

                      

        }          

        

  

   

   }

    Write-Host "`n`tEnd of Filer: $filer "

   # Close

   }

Re: Lun information the way I want it...

This is bad ass! anyway to expor the results to .csv?

Re: Lun information the way I want it...

Thanks..

I haven't looked at it in a while.. If I get some free time, I'll see what I can do. I'm pretty slammed these days...

It's all about creating objects and exporting them to excel. 

Re: Lun information the way I want it...

Very good stuff!  I wrote a script some time ago that does the same thing.  THis can be exported to Excel:

function GetIgroupHost()

{

  <#

    .SYNOPSIS

    Returns the name of the Host Server mapped to the given igroup.  It parses the iGroup name to get this information, and assumes the iGroup was automatically created by SnapDrive.

 

    .PARAMETER iGroup

    The iGroup object to get the host from. 

   

    .EXAMPLE

    $hosts = Get-NaIgroup | GetIgroupHost

   

  #>

  param

  (

    [Parameter(Mandatory=$true,ValueFromPipeline=$true)] $iGroup

  )

 

  process

  {

    $hostName = ""

   

    if ( $iGroup )

    {

      if ( ($iGroup.Name -split "\.").Count -gt 1 )

      {

        $hostName = ($iGroup.Name -split "\.")[2]

      }

      else

      {

        $hostName = $iGroup.Name

      }

    }

   

    return $hostName

  }

}

function GetConnectedController()

{

  <#

    .SYNOPSIS 

    Returns the currently-connected controller if one exists.

  #>

 

  if ( (Get-Variable | ? { $_.Name -ieq "global:CurrentNaController" }) -and $global:CurrentNaController )

  {

    return $global:CurrentNaController

  }

}

function GetVolumes()

{

  param

  (

    [Parameter(Position=0)][string] $NameFilter,

    $Controller   

  )

  <#

    .SYNOPSIS

    Helper function that retrieves the volumes from a NetApp controller, including any luns and mappings.  Adds the following properties:

    [Volume].Luns[]

      .[Lun].Maps[]

      .[Lun].Mappedto(string)

     

    .PARAMETER Controller

    If specified, then queries the given controller.  Can specify either a controller name or Controller Connection (from Connect-NaController).  If unspecified, then uses the currently-connected controller.  If no

      controller is connected, it will prompt you.

   

    .PARAMETER NameFilter

    If specified, uses the given value as a regex and only returns volumes whose names match the filter.

   

    .EXAMPLE

    Connect-NaController ctrl1 -RPC

    GetVolumes

   

    .EXAMPLE

    GetVolumes -Controller ah-3240-1 -NameFilter monitor

   

  #>

 

  $ctrlConnection = $null

 

  if ( !$Controller )

  {

    #  Controller not specified:

    if ( GetConnectedController )

    {

      #  Use already-connected controller:

      $ctrlConnection = GetConnectedController

    }

    else

    {

      #  Controller not specified:

      $Controller = Read-Host "Specify a controller to query"

      $ctrlConnection = Connect-PlexController -Controller $Controller -Passthru

    }

  }

  else

  {

    #  Controller specified:

    if ( $Controller -is [string] )

    {

      $ctrlConnection = Connect-PlexController -Controller $Controller -Passthru -Transient   

    }

    else

    {

      $ctrlConnection = $Controller

    }

  }

 

  if ( !$ctrlConnection -or $ctrlConnection -isnot [NetApp.Ontapi.Filer.NaController] )

  {

    #  No controller specified, or invalid:

    throw ("You must either specify -Controller or be already connected to one before calling this function!")

  }

   

  $vols = Get-NaVol -Controller $ctrlConnection | ? { !$NameFilter -or $_.Name -imatch $NameFilter }

 

  foreach ( $vol in $vols )

  {

    $luns = @(Get-NaLun -Controller $ctrlConnection -Terse -Path ("/vol/{0}/*" -f $vol.Name))

   

    $vol | Add-Member -MemberType NoteProperty -Name "luns" -Value $luns

   

    if ( $luns )

    {

      foreach ( $lun in $luns )

      {

        $maps = @($lun | Get-NaLunMap -Controller $ctrlConnection)

        $lun | Add-Member -MemberType NoteProperty -Name "maps" -Value $maps      

        $lun | Add-Member -MemberType ScriptProperty -Name "MappedTo" -Value `

        {

          if ( $this.maps )

          {

            $this.maps | getigrouphost

          }

        }

      }

    }

  }

 

  $vols

}

$controllers = "filer1","filer2"

$vols = @()

foreach ( $ctrl in $controllers )

{

  Connect-NaController $ctrl -RPC

  $vols += GetVolumes

}

#  Export to Excel

$vols | % { $_.Luns } | Select-Object @{"Label"="volume";"expression"={($_.path -split "/")[2]}},Path,MappedTo | Export-Csv -NoTypeInformation -Path C:\Temp\excel.csv