Subscribe
Accepted Solution

Powershell script to show LUN Name, LUN Size and Mapped Igroup (7-Mode)

[ Edited ]

Hi Guys,

 

In cases where you need to know to which Igroup a LUN is mapped to (7-Mode script):

 

Param(
    [Parameter(Mandatory=$true)]
    [string]$Filer
)

function Get-LUNData($LUN){
    $LunPath = $LUN.Path
    $LunSize=$LUN.Size # Size in bytes

    Get-NaLunMap -Path $LunPath -Controller $Connection|ForEach-Object{
        $output = New-Object psobject
        $Map=$_

        $output |Add-Member NoteProperty "LUN Path" $LunPath
        $output |Add-Member NoteProperty "Size (GB)" ("{0:N0}" -f ($LunSize / 1GB))
        $output |Add-Member NoteProperty "Mapped to" $Map.Name

        Write-Output $output
            
    }
}

if(-not $Credential) {
    $Credential = Get-Credential
}

$Connection = Connect-NaController $Filer -HTTPS -Credential $Credential -Transient

if(-not $Connection){
    Exit -1
}

Get-NaLun -Controller $Connection|ForEach-Object{
    Get-LUNData -LUN $_
}

 

You can even export it to CSV file easily:

 

Get-LUNInfo.ps1 -Filer [filer name] |Export-Csv -Path MyCSVFile.csv -NoTypeInformation -Delimiter ";"

 

Maybe someone needs it.

Re: Powershell script to show LUN Name, LUN Size and Mapped Igroup (7-Mode)

Hi @FelipeMafra,

 

Great work, and thank you for helping the community.  If you're willing to send me your address (in a private message please) I'd be happy to mail you some NetApp stickers.

 

For clustered Data ONTAP users, you can get similar information using this bit of script:

 

Get-NcLun | Select Path,`
    @{N='Size';E={ $_.Size | ConvertTo-FormattedNumber }},`
    @{N='SizeUsed';E={ $_.SizeUsed | ConvertTo-FormattedNumber }},`
    Online,`
    Mapped,`
    @{N='igroup';E={ (Get-NcLunMap -Path $_.Path).InitiatorGroup }} | Format-Table -AutoSize

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Re: Powershell script to show LUN Name, LUN Size and Mapped Igroup (7-Mode)

Thanks for the Script,   Can you help me resolve the below error that PS is throwing back to back when I run this script.

 

Get-LUNInfo : The term 'Get-LUNInfo' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was
included, verify that the path is correct and try again.
At D:\Automation\Lun_Info.ps1:34 char:5
+ Get-LUNInfo -LUN $_
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-LUNInfo:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Re: Powershell script to show LUN Name, LUN Size and Mapped Igroup (7-Mode)

Hello @Pramod_Kumar,

 

It appears to be a bug/typo in the script.  The line should be 

 

Get-LUNData -LUN $_

Andrew

If this post resolved your issue, please help others by selecting ACCEPT AS SOLUTION or adding a KUDO.

Re: Powershell script to show LUN Name, LUN Size and Mapped Igroup (7-Mode)

Thanks @asulliva

 

It working as expected now. 

Re: Powershell script to show LUN Name, LUN Size and Mapped Igroup (7-Mode)

[ Edited ]

Exactly,

 

I misspelled since my script name is Get-LUNInfo. I've just fixed original post.

 

Re: Powershell script to show LUN Name, LUN Size and Mapped Igroup (7-Mode)

Thanks @FelipeMafra

 

 

Can you plase help me with the below as well

 

Get-LUNInfo.ps1 -Filer pr-netapp-01 |Export-Csv -Path pr-netapp-01.csv -NoTypeInformation -Delimiter ";"

 

when I run the above at powershell it gives the below error. I might be running it wrong. 

 

 

Get-LUNInfo.ps1 : The term 'Get-LUNInfo.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path
was included, verify that the path is correct and try again.
At line:1 char:1
+ Get-LUNInfo.ps1 -Filer pr-netapp-01 |Export-Csv -Path pr-netapp-01.csv -NoTypeIn ...
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-LUNInfo.ps1:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Re: Powershell script to show LUN Name, LUN Size and Mapped Igroup (7-Mode)

Save the first source code using this name: Get-LUNInfo.ps1 then you'll be able to use it.