Software Development Kit (SDK) and API Discussions

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

FelipeMafra

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.

1 ACCEPTED SOLUTION

asulliva

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.

View solution in original post

7 REPLIES 7

asulliva

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.

View solution in original post

Pramod_Kumar

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

asulliva

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.

Pramod_Kumar

Thanks @asulliva

 

It working as expected now. 

FelipeMafra

Exactly,

 

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

 

Pramod_Kumar

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

FelipeMafra

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

Announcements
NetApp on Discord Image

We're on Discord, are you?

Live Chat, Watch Parties, and More!

Explore Banner

Meet Explore, NetApp’s digital sales platform

Engage digitally throughout the sales process, from product discovery to configuration, and handle all your post-purchase needs.

NetApp Insights to Action
I2A Banner
Public