Software Development Kit (SDK) and API Discussions

Powershell command/script to display lun name only (without full path)? (Get-NaLUN)

gaulden
2,542 Views

Our customer (running Ontap 9.7) has a need to obtain output that displays LUN names only, however when using the host utilities kit  (v7.1)they see that the output won't show just the LUN name, but instead includes the entire path to the LUN.

 

For Linux, we have a workaround for the 'sanlun lun show' command by using the following command to extract the LUN names:

sanlun lun show | grep vol | awk '{print $2}' | cut -d '/' -f 4

 

Trying to figure out a similar workaround for them for Windows, possibly using the Netapp Powershell toolkit and the 'Get-NaLUN' command. Anyone out there have thoughts on how to script this to make it viable?

 

 

2 REPLIES 2

JohnChampion
2,487 Views

Using the NetApp PowerShell Toolkit...hope this helps...

 

FYI - ONTAP 9.7 would use the "-Nc*" cmdlets - not the "-Na*". 

 

 

Connect-NcController {clusterip}

$luns = (Get-NcLun).Path

 foreach ( $lun IN $luns ) {
     $lun_path = $lun.Split("/")
     $lun_name = $lun_path[$lun_path.count-1]
     $lun_name
}

 

 

donny_lang
2,485 Views

Regex to the rescue! 

 

$Luns = Get-NcLun
foreach ($lun in $luns) { $lun.Path -replace '(?s)^.*\/', '' }
Public