Microsoft Virtualization Discussions

Getting igroup and Lun information the way I want...

JGPSHNTAP
8,504 Views

I'm wondering if i'm over thinking this.. I know there are tons of cmdlets with lun and igroup mapping, but I put this together b/c it gets what I want... 

Let me know what you think and if I overcomplicated things.

$hosts = @("filer1","filer2")

$hosts | % {

   

   Write-Host "`nConnecting to Filer: $_"

    $c  = Connect-NaController $_

   

    $igroup = Get-NaIgroup

    $Luninfo = Get-NaLun | ? {$_.path -notlike "*sv*"} | % {  Get-NaLunMap $_.path }

      

    foreach ($i in $igroup) {

        

         # Set igroup variable

         $igroup = $i.name

        Write-Host "igroup Name: " $I.Name

        Write-Host "`t`tType: " $i.type

        $type = $i.type

        Write-Host "`t`tOS: "   $i.protocol

        $iprotocol = $i.protocol

        Write-Host "`t`tinitiators: " $i.initiators

        $iinitiators = $i.initiators

   

            foreach ($l in $Luninfo) {

              if ($igroup -eq $l.name)

              {

              Write-Host "`t`tLun Path: " $l.path

               $lunpath = $l.path

              Write-Host "`t`tLunID: " $l.lunid

               $lunid = $l.lunid

              }

             

           

            }

             

       

         

          }

         

          Write-Host "`n`n"

}

       

       

}

9 REPLIES 9

JGPSHNTAP
8,505 Views

Hmm.. Ok, I have  a fundamental bug in the script which I just caught.. If you have more than 4 initiators in the output gets cut off..

So then i tried to change the following line

# $igroup = Get-NaIgroup

to

    $igroup =  get-naigroup | select Name,type,Protocol -expandproperty Initiators

And now my initiators are blank... upon output.. I'm not quite sure why that is happening..  I see them their in $igroup, so why when I try to parse them

So, then I realize that we need to change this line

   Write-Host "`t`tinitiators: " $i.initiators

        $iinitiators = $i.initiators

to

write-host "`tInitiators: " $i.initatornames

     

But then it messes up the output..

What im ultimately looking for is for all the initiators to be on the same line separate by a space so then I can work with the output.

any guidance or direction would be great.

thx

sizemore
8,505 Views

Have you tried:

Get-Nalun | Get-Nalunmap | Format-Table

we wrote that format output to handle this general usecase.

~Glenn

JGPSHNTAP
8,505 Views

Yeah.. i went through that as well..

Your code still prodocues my same problem

Name   LunID Initiators

----   ----- ----------

igroupname 11    {50:01:43:80:05:67:55:4e, 50:01:43:80:05:67:5b:0c, 50:01:43:80:05:67:5a:e4, 50:01:43:80:05:67:55:54...}

The reason I need to do all this is b/c i need to setup an exact same filer with igroups and lun mappings for DR.. it's a long story.. but i thought i was on easy streat until i noticed the initiators truncated

I'm taking the output of these commands and i'm parsing through the output to do eventually create a command

new-naigroup -name $name -protocol $protocl -type $type

I can pretty much get to dthat, it's all the rest of the automation that's coming along.

sizemore
8,505 Views
Oh no, your doing that the hard way.  You don't need to parse the text to recreate the Igroups/lun maps, just use the objects.
As a general example however I refactored your code snippit.
$hosts = @("NTAPA","NTAPB")            
            
$hosts | % {            
   Write-Host "`nConnecting to Filer: $_"            
   $c  = Connect-NaController $_            
   $igroups = Get-NaIgroup            
   $LunInfo = Get-NaLun -Terse | where-object {$_.path -notlike "*sv*"} | Get-NaLunMap | Group-Object Name            
   foreach ($igroup in $igroups) {            
       Write-Host "`tigroup Name: " $Igroup.Name            
       Write-Host "`t`tType: " $Igroup.type            
       Write-Host "`t`tOS: "   $Igroup.protocol            
       Write-Host "`t`tinitiators: " $(($igroup.initiators|Select-Object -ExpandProperty InitiatorName) -join "`n`t`t`t     ")            
       Write-Host "`t`tLuns:   LUN ID   LUN Path"            
       Write-Host "`t`t`t------   ------------------------------------------"            
       foreach ($lun in ($Luninfo| where {$_.Name -eq $igroup.Name} | select -ExpandProperty Group)) {            
               Write-Host ("`t`t`t  {0:0}      {1}" -f $lun.lunid, $lun.path)            
       }            
    }            
}

JGPSHNTAP
8,505 Views

Glenn -

Yuu absolutely rock right now.!!  I loved your note on replicating igroups to another filer b/c that is essentially what I want to do...  I had thoughts of doing it your way but I figured i would be safe and dump to a file and then run another script..

From a reporting standpoint your script kicks butt!.. But if I'm going to replicate everything to another filer, igroups, lunID's, mapping etc, I'm going to need to put it in a little different format..

Where was I going wrong with my original script?  A few ?'s for you.  I see you ran -Group Name for this line -

$LunInfo = Get-NaLun -Terse | where-object {$_.path -notlike "*sv*"} | Get-NaLunMap | Group-Object Name  

I'm just curious as to why you did grouping by name?  is that so it truncates the initiators? 

Also, when you use select-object, I understand expandproperty - but -join does what? 

Also, i'm not quite sure what you're doing with this -

Write-Host ("`t`t`t  {0:0}      {1}" -f $lun.lunid, $lun.path)

what's {0:0}     {1} and -f   I did a man on write-host but it didn't lead me to it..

Also, since you are the expert, and I need to replicate this entire configuration, I was going to try to dump it to a file and then read through the file to build the scripts I need for our DR filer.  Is that totally off base?

Thanks in advance..

JGPSHNTAP
8,505 Views

Glenn -

For now, I just modified it a little bit

$hosts | % {           

   Write-Host "`nConnecting to Filer: $_"           

   $c  = Connect-NaController $_           

   $igroups = Get-NaIgroup           

   $LunInfo = Get-NaLun -Terse | where-object {$_.path -notlike "*sv*"} | Get-NaLunMap | Group-Object Name           

   foreach ($igroup in $igroups) {           

       Write-Host "`tigroup Name: " $Igroup.Name           

       Write-Host "`t`tOS_Type: " $Igroup.type           

       Write-Host "`t`tProtocol: "   $Igroup.protocol           

       Write-Host "`t`tinitiators: " $(($igroup.initiators|Select-Object -ExpandProperty InitiatorName) -join " ")           

       Write-Host "`t`tLuns  ------   ------------------------------------------" # LUN ID   LUN Path"           

       foreach ($lun in ($LunInfo| where {$_.Name -eq $igroup.Name} | select -ExpandProperty Group)) {  

                Write-Host "`t`t`tLunID: "  $lun.lunid

                Write-Host "`t`t`tLun Path: " $lun.path   

               #Write-Host ("`t`t`t  {0:0}      {1}" -f $lun.lunid, $lun.path)           

       }           

    }           

}

I sole did this with the intention of dumping to a file and replicating configurations...

JGPSHNTAP
8,505 Views

Glenn and team:

So i'm just playing out with the output a little before the next step, but I have a ?

        foreach ($lun in ($LunInfo| where {$_.Name -eq $igroup.Name} | select -ExpandProperty Group)) {                     Write-Host "`t`t`tLUN:" $lun.lunID ":" $lun.path                                 } 

I was looking at $luninfo, and i'm not quite sure how you got $lun.lunid and $lun.path.. And the reason I ask is b/c I tried do something like

if ($lun.lunid -ne $null) {

Write-Host "`t`t`tLUN:" $lun.lunID ":" $lun.path    

}

else

{write-host "No active mappings"}

But my results were not what I thought they would be..

all thoughts are well appreciated.

thx

JGPSHNTAP
8,505 Views

Ah.. Ok, i'm getting a frustrated as i've looked at your examples, but i'm unable to replicate the initiators...


Here is the code extracted and modified a little.

$sourcecontroller = Connect-NaController source

$dstcontroller = Connect-NaController destination

$igroups = Get-NaIgroup -Controller $sourcecontroller

## Loop through existing $igroup info

foreach ($Igroup in $igroups) {

   if ($Igroup.name -eq "testigroup")

   {

    #WRite-out command for testing igroup creation"

    Write-Host "`nCreating Igroup:" $Igroup.name "On controller" $dstcontroller

    Write-Host "--------------------------------------------------------"

    New-NaIgroup -Name $Igroup.Name -Type $Igroup.type -protocol $Igroup.protocol -controller $dstcontroller -confirm:$false

   

    ## write-out command for testing adding initiators"

    $Initiators = $iGroup.Initiators | Select-Object -ExpandProperty 'InitiatorName'

     Add-naigroupinitiator -igroup $igroup.name -initiator $Initiators -Controller $dstcontroller -confirm:$false -whatif

    Write-Host "`n"

}

}

That will create an igroup without issue but the Add-naigroupinitiator spits up errors at me. 

Add-NaIgroupInitiator : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'Initiator'. Specified method is not supported.

At C:\Powershell\sg colo\igroupcreationAnode.ps1:32 char:55

+     Add-naigroupinitiator -igroup $igroup.name -initiator <<<<  $Initiators -Controller $dstcontroller -confirm:$false -whatif

    + CategoryInfo          : InvalidArgument: (:) [Add-NaIgroupInitiator], ParameterBindingException

    + FullyQualifiedErrorId : CannotConvertArgument,DataONTAP.PowerShell.SDK.Cmdlets.Igroup.AddNaIgroupInitiator

now if i manually just enter one initiator it works.. but it doesn't handle the mutliple initators well.   Also in your code example, I'm not seeing where you add any initiators

Your posted code has this.

# Add any missing initiators from the source

$Initiators = $I.Initiators |

Select-Object -ExpandProperty 'InitiatorName'

$IGroup.Initiators |

Where-Object { $Initiators -notContains $_.InitiatorName } |

Add-NaIgroupInitiator -Igroup $I.InitiatorGroupName ` -Controller $DestinationController

Did I miss something?   Can add-nainitiator not handle multiple initiators.  like

add-naigroupinitiator -igroup testigroup -initiator 50:01:43:80:05:67:55:4e,50:01:43:80:05:67:5b:0c -Controller dstcontroller

what gives here?

JGPSHNTAP
8,504 Views

Glenn -

Excuse my oversight.. I See that you have piped in $initiators

Once I adjusted this line - $Initiators | Add-NaIgroupInitiator -igroup $igroup.name  -Controller $dstcontroller -confirm:$false

it's working like a charm.. I did  man on it and saw that it accepts pipeline input.

So, what's the technical reason why my code will fail?  Is it because it's an array and the cmdlet doesn't know how to interpret it?  Just curious...

Public