PowerShell Script Function to Get Lun Information for a Particular InitiatorGroup Name & Lunid

Here's a custom PowerShell Script Using PS ToolKit to extract Lun Information for a Particular InitiatorGroup Name & Lunid.

 

function Get-NaLUNbyMap {

<#

.DESCRIPTION

Gets Lun Information for a Particular InitiatorGroup Name & Lunid

.EXAMPLE

Import-Module NaLUNbyMap

Get-NaLUNbyMap -igroup "viaRPC.iqn.1991-05.com.microsoft:demombxcashub.smedemo.com" -LunID 1

Get-NaLUNbyMap -igroup "viaRPC.iqn.1991-05.com.microsoft:demombxcashub.smedemo.com" -LunID 1 | Export-Csv "Filer.csv"

#>

 

 

[CmdletBinding()]

param(

                    [Parameter(Mandatory=$True,ValueFromPipeline=$True,HelpMessage="InitiatorGroupName")]

                    $igroup,

                    [Parameter(Mandatory=$True,ValueFromPipeline=$True,HelpMessage="LunID")]

                    $LunID

           )

 

$info=(Get-NaLun | Select @{Name="LUN";Expression={$_.path}},@{Name="Size";Expression={[math]::Round([decimal]$_.size/1gb,0)}},@{Name="OnlineStatus";Expression={$_.online}},@{Name="Group";Expression={([string]::Join(",",(Get-NaLun $_.path | get-nalunmap | select -ExpandProperty initiatorgroupname)))}},@{Name="LunID";Expression={Get-NaLun $_.path | get-nalunmap | select -ExpandProperty lunid}} | ?{$_.group -eq $igroup -and $_.lunid -eq $lunid})

 

 

Return $info

}

 

 

I can also pipe the output of this cmdlet to "Export-CSV" to extract the data in a csv format.

 

Comments

Vinith -

I've posted this code in the past..   - I should update it for custom objects.. When I get time I will....

$hosts = "filera"


$hosts | % {           
   Write-Host "`n`tConnecting to Filer: $_"
   $filer = $_ 
   Write-Host "`t-------------------------------------------------------"        
   $c  = Connect-NaController $_           
   $igroups = Get-NaIgroup           
   $LunInfo = Get-NaLun -Terse | where-object {$_.path -notlike "*sv*"} | 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
   }
   

vinith Former NetApp Employee

Yes, we should avoid using as much write-host as possible, and emit custom objects.

Totally agree...

Hi vinit

can i get module file.. .