Microsoft Virtualization Discussions

PSTK: Combine the output of Get-NcLunMap and Get-NcIgroup - custom object?

tyrone_owen_1
4,940 Views

Hi,

 

So I want to combine the output from the following two cmdlets:

 

Get-NcLunMap | Select-Object Vserver,Path,InitiatorGroup,LunId
Get-NcIgroup | Select-Object InitiatorGroupAluaEnabled,InitiatorGroupOsType,InitiatorGroupType,Initiators

 

I've been looking at the Don Jones video, https://www.youtube.com/watch?v=TLUzPvA0HUo&t=42s, and I think I need to create a custom object. The cmdlets in the video return a single item, e.g. for a particular computer the Win32_OperatingSystem, however Get-NcLun/Igroup returns all of the LUNs/Igroups from a cluster.  I can see how the Don Jones example would work for a single item but I don't understand how to upscale that when there are multiple objects returned.

 

Also as an aside, is there any way I can get an online/offline status for initiators into my completed table?

 

As you can probably tell, I'm a novice, any thoughts please?

 

Thanks

 

 

1 ACCEPTED SOLUTION

jcolonfzenpr
4,847 Views

Hi:

 

Check the attached document. It includes example code.

 

Hope this help!

 

OntapLuninfo.ps1

vServer Lun ID IGROUP Name            IGROUP TYPE IGROUP TYPE OS IGROUP ALUA ENABLE Lun Path                              
------- ------ -----------            ----------- -------------- ------------------ --------                              
SAN          0 comp-01a               mixed       vmware                       True /vol/SERVER_DATASTORE/SERVER_DATASTORE



Initiator                                        Online
---------                                        ------
iqn.1998-01.com.vmware:comp-01a-62411b9cdd7438fb True  
iqn.1998-01.com.vmware:comp-02a-92411b9cdd7438fb False 
iqn.1998-01.com.vmware:comp-03a-42411b9cdd7438fb False 
iqn.1998-01.com.vmware:comp-04a-52411b9cdd7438fb False 



vServer Lun ID IGROUP Name            IGROUP TYPE IGROUP TYPE OS IGROUP ALUA ENABLE Lun Path                                         
------- ------ -----------            ----------- -------------- ------------------ --------                                         
SAN          2 comp-01a               mixed       vmware                       True /vol/SERVER_DATASTORE_VVOL_1/vvolPE-1614476525287



Initiator                                        Online
---------                                        ------
iqn.1998-01.com.vmware:comp-01a-62411b9cdd7438fb True  
iqn.1998-01.com.vmware:comp-02a-92411b9cdd7438fb False 
iqn.1998-01.com.vmware:comp-03a-42411b9cdd7438fb False 
iqn.1998-01.com.vmware:comp-04a-52411b9cdd7438fb False 
Jonathan Colón | Blog | Linkedin

View solution in original post

5 REPLIES 5

tyrone_owen_1
4,875 Views

So after a bit more research I came across this approach, however it still doesn't get me what I want:

function Get-CgiNcLunMapInfo ()
{
    
    $lunmapinfo = Get-NcLunMap
    $igroupinfo = Get-NcIgroup

    # Create custom object for $lunmapinfo
    # Empty array
    $lunmapinfoobjs = @()

    # Loop to set up a single custom object
    foreach ($lun in $lunmapinfo) {
    
        $props = @{ Vserver = $lun.Vserver
                    Path = $lun.Path
                    LunId = $lun.LunId
                    Igroup = $lun.InitiatorGroup
                    }
 
        $lunmapinfoobj = New-Object -TypeName PSObject -Property $props
 
        # Append to array
        $lunmapinfoobjs += $lunmapinfoobj
 
    }


    # Create custom object for $igroupinfo
    # Empty array
    $igroupinfoobjs = @()

    # Loop to set up a single custom object
    foreach ($igroup in $igroupinfo) {
    
        $props = @{ Igroup = $igroup.Name
                    Alua = $igroup.InitiatorGroupAluaEnabled
                    OsType = $igroup.InitiatorGroupOsType
                    GroupType = $igroup.InitiatorGroupType
                    Initiators = $igroup.Initiators 
                    }

        $igroupinfoobj = New-Object -TypeName PSObject -Property $props

        # Append to array
        $igroupinfoobjs += $igroupinfoobj

    }

    $props = @{ LunInfo = $lunmapinfoobjs
                IgroupInfo = $igroupinfoobjs
                }


    $obj = New-Object -TypeName PSObject -Property $props

    Write-Output $obj

}

 

The above script pushes the Get-NcLunMap objects/properties under the heading 'LunInfo' and the Get-NcIgroup objects/properties under the heading 'IgroupInfo', whereas I want to combine the properties into a single table, e.g.

 

Path,LunId,Igroup,Vserver,Alua,Igroup,OsType,GroupType,Initiators 

 

Thanks

jcolonfzenpr
4,848 Views

Hi:

 

Check the attached document. It includes example code.

 

Hope this help!

 

OntapLuninfo.ps1

vServer Lun ID IGROUP Name            IGROUP TYPE IGROUP TYPE OS IGROUP ALUA ENABLE Lun Path                              
------- ------ -----------            ----------- -------------- ------------------ --------                              
SAN          0 comp-01a               mixed       vmware                       True /vol/SERVER_DATASTORE/SERVER_DATASTORE



Initiator                                        Online
---------                                        ------
iqn.1998-01.com.vmware:comp-01a-62411b9cdd7438fb True  
iqn.1998-01.com.vmware:comp-02a-92411b9cdd7438fb False 
iqn.1998-01.com.vmware:comp-03a-42411b9cdd7438fb False 
iqn.1998-01.com.vmware:comp-04a-52411b9cdd7438fb False 



vServer Lun ID IGROUP Name            IGROUP TYPE IGROUP TYPE OS IGROUP ALUA ENABLE Lun Path                                         
------- ------ -----------            ----------- -------------- ------------------ --------                                         
SAN          2 comp-01a               mixed       vmware                       True /vol/SERVER_DATASTORE_VVOL_1/vvolPE-1614476525287



Initiator                                        Online
---------                                        ------
iqn.1998-01.com.vmware:comp-01a-62411b9cdd7438fb True  
iqn.1998-01.com.vmware:comp-02a-92411b9cdd7438fb False 
iqn.1998-01.com.vmware:comp-03a-42411b9cdd7438fb False 
iqn.1998-01.com.vmware:comp-04a-52411b9cdd7438fb False 
Jonathan Colón | Blog | Linkedin

tyrone_owen_1
4,790 Views

That's brilliant - thank you

 

I've played around with the script to try and get a single table as opposed to individual tables per LUN path, something like this:

 

vServer Lun ID IGROUP Name            IGROUP TYPE IGROUP TYPE OS IGROUP ALUA ENABLE Lun Path                                         
------- ------ -----------            ----------- -------------- ------------------ --------                                         
SAN          2 comp-01a               mixed       vmware                       True /vol/SERVER_DATASTORE_VVOL_1/vvolPE-1614476525287
SAN          0 comp-01a               mixed       vmware                       True /vol/SERVER_DATASTORE/SERVER_DATASTORE
SAN          0 comp-01a               mixed       vmware                       True /vol/SERVER_DATASTORE/SERVER_DATASTORE2

 

Can the script be tweaked to achieve this?

 

Thanks again

jcolonfzenpr
4,779 Views

only need to change one line of the code. put a # in front of:

 

#Write-Output $initiatoronline
Jonathan Colón | Blog | Linkedin

tyrone_owen_1
4,745 Views

Thank again for your help

 

I thought that, but the output looks like this instead of consolidated under one heading:

 

vServer Lun ID IGROUP Name            IGROUP TYPE IGROUP TYPE OS IGROUP ALUA ENABLE Lun Path                                         
------- ------ -----------            ----------- -------------- ------------------ --------                                         
SAN          2 comp-01a               mixed       vmware                       True /vol/SERVER_DATASTORE_VVOL_1/vvolPE-1614476525287

vServer Lun ID IGROUP Name            IGROUP TYPE IGROUP TYPE OS IGROUP ALUA ENABLE Lun Path                                         
------- ------ -----------            ----------- -------------- ------------------ -------- 
SAN          0 comp-01a               mixed       vmware                       True /vol/SERVER_DATASTORE/SERVER_DATASTORE
vServer Lun ID IGROUP Name            IGROUP TYPE IGROUP TYPE OS IGROUP ALUA ENABLE Lun Path                                         
------- ------ -----------            ----------- -------------- ------------------ -------- 
SAN          0 comp-01a               mixed       vmware                       True /vol/SERVER_DATASTORE/SERVER_DATASTORE2

 

Public