Software Development Kit (SDK) and API Discussions

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

FelipeMafra
9,338 Views

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
9,296 Views

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
9,297 Views

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.

Pramod_Kumar
8,658 Views

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
8,650 Views

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
8,646 Views

Thanks @asulliva

 

It working as expected now. 

FelipeMafra
8,642 Views

Exactly,

 

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

 

Pramod_Kumar
8,638 Views

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
8,602 Views

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

Public