• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1091
  • Last Modified:

Powershell Hashtable please help

I am trying to work with a hash table Named $results

Once I run a script that loads $results I can then navigate

$results["a"][0]["items"]

Here are the results
Itemname                       000-555
itemmaker                       HenryX
itemnumber                        20
locations                           {}
itemmaker                       HenryX
itemnumber                         21
locations                           {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...
Itemname                       000-222
itemmaker                       HenryX
itemnumber                         22
locations                           {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...
Itemname                       000-333
itemmaker                       HenryX
itemnumber                         23

I can also navigate to for example item name

$results["a"][0]["items"][22][itemname]
000-222

I want to be able to pull all the info from all of the itemname values and all of itemmaker values and itemnumber I also want to be able to get all of the info from producer which is located $results[producer]  I would like to take all of this info and out-file it to a text file so in the end it looks like
Producer             ItemName         Itemmaker       Itemnumber
John Henry               000-555        HenryX                  21
John Henry               000-222        HenryX                  22
John Henry               000-333        HenryX                   23

Any suggestions on how this can be done?


0
dmc2084
Asked:
dmc2084
  • 10
  • 9
1 Solution
 
Chris DentPowerShell DeveloperCommented:

If you could give us an example of the structure you've built it would help enormously. Ideally with the code to build it since reproducing it takes more time than would seem useful.

Chris
0
 
dmc2084Author Commented:
Unfortunately I do not have access to the guts of the script at this time.
I will try to explain.  
       The script is first run by piping a list of hosts in question into it
            Cat c:\Hostlist.txt | hashtablescript.ps1
                  
     The script pulls a lot of info that is thrown into a hash table with multiple keys(values?) It is pulling things like mac addresses, nic id, nic location

cat "c:\hostlist.txt" | c:\hashtablescript.ps1

Once script completes, results are saved in $results
$results output follows
Name                           Value
----                           -----
hostname                       host1
nics                           {System.Collections.Hashtable, System.Collections.Hashtable}
hostname                       host2
nics                          {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...
hostname                       host3
nics                           {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...
hostname                       host4
nics                          {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...

lets say I need the nic information for host4 so I navigate to nics key       $results[3][nics]    
[3] is selecting hash results for host 4 only.  

( $results[0][nics]   would select results for host 1)

The hosts are counted from the top down 0,1,2,3

The following is the output from  $results[3][nics]    




Name                           Value
----                           -----
id                         453645
local                    1
info                        1
mac                       453453453
items                        {}
serial                       453453543
id                         45345345
local                    0
info                        1
mac                       453453453
items                        {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...
serial                       45345353
id                         453453453
local                    1
info                        1
mac                       453453453
items                        {}
serial                       45345345

I need to see more info about the mac and serial so I navigate to where they are contained
 $results[3][nics][1][items]      no matter what host it is [1][items] will always get you to items key

Output is as follows  $results[3][nics][1][items]      

mac                      4545645645
serial                     453453453
LocationID                         7
connections                           {}

mac                       45645645
serial                       456456
LocationID                         8
connections                           {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...

mac                       456456
serial                       456456
LocationID                         9
connections                           {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...

mac                       456456
serial                       456456
LocationID                         10
connections                           {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...

Any LocationID that does not have a connections name that contains System.Collections.Hashtable is empty and will not need to be selected.  

So for example LocationID 10 has information in it so now to navigate to it and get the results for mac and serial for everything that contains System.Collections.Hashtable  or is not like {}.  


Results for Location 9 and 10
$results[3][nics][1][items][10][mac]
456456
$results[3][nics][1][items][10][serial]
456456

$results[3][nics][1][items][9][mac]
456456
$results[3][nics][1][items][9][serial]
456456

I want to be able to out-file Macs and serials to a text file with the content looking like
Host        mac         serial
Host1    456456     45645
Host2    55456       54545
Host3    54546        6546

Just a hint as to how I may do this will send me in the right direction.



0
 
dmc2084Author Commented:
Cleaning up last post

Unfortunately I do not have access to the guts of the script at this time.
I will try to explain.  
       The script is first run by piping a list of hosts in question into it
            Cat c:\Hostlist.txt | hashtablescript.ps1
                 
     The script pulls a lot of info that is thrown into a hash table with multiple keys(values?) It is pulling things like mac addresses, nic id, nic location

cat "c:\hostlist.txt" | c:\hashtablescript.ps1

Once script completes, results are saved in $results
$results output follows
Name                           Value
----                           -----
hostname                       host1
nics                           {System.Collections.Hashtable, System.Collections.Hashtable}
hostname                       host2
nics                          {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...
hostname                       host3
nics                           {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...
hostname                       host4
nics                          {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...

lets say I need the nic information for host4 so I navigate to nics key       $results[3][nics]    
[3] is selecting hash results for host 4 only.  

( $results[0][nics]   would select results for host 1)

The hosts are counted from the top down 0,1,2,3

The following is the output from  $results[3][nics]    




Name                           Value
----                           -----
id                         453645
local                    1
info                        1
mac                       453453453
items                        {}
serial                       453453543
id                         45345345
local                    0
info                        1
mac                       453453453
items                        {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...
serial                       45345353
id                         453453453
local                    1
info                        1
mac                       453453453
items                        {}
serial                       45345345

I need to see more info about the mac and serial so I navigate to where they are contained
 $results[3][nics][1][items]      no matter what host it is [1][items] will always get you to items key

Output is as follows  $results[3][nics][1][items]      

mac                      4545645645
serial                     453453453
LocationID                         7
connections                           {}

mac                       45645645
serial                       456456
LocationID                         8
connections                           {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...

mac                       456456
serial                       456456
LocationID                         9
connections                           {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...

mac                       456456
serial                       456456
LocationID                         10
connections                           {System.Collections.Hashtable, System.Collections.Hashtable, System.Collections.Hasht...

Any LocationID that does not have a connections name that contains System.Collections.Hashtable is empty and will not need to be selected.  

So for example LocationID 10 has information in it so now to navigate to it and get the results for mac and serial for everything that contains System.Collections.Hashtable  or is not like {}.  


Results for Location 9 and 10
$results[3][nics][1][items][10][mac]
456456
$results[3][nics][1][items][10][serial]
456456

$results[3][nics][1][items][9][mac]
456456
$results[3][nics][1][items][9][serial]
456456

I want to be able to out-file Mac  and serials to a text file with the content looking like
Host        mac         serial
Host1    456456     45645
Host2    55456       54545
Host3    54546        6546

Just a hint as to how I may do this will send me in the right direction.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
Chris DentPowerShell DeveloperCommented:

It's pretty messy. I thought about collapsing the nested Hash Tables into a single flat object, but it's probably not worth the effort (it's far more code and complexity) if all you need are those three values.

I've included an example of how I constructed the hash table (right at the bottom) based on the descriptions above. And a fairly nasty bit of looping that returns an Object containing each of the values you're looking for.

You can either export that to a CSV with:

$Results | Export-CSV "SomeFile.csv"

Or it can be directed to a text file. Export-CSV is likely to be neater though.

Is this the kind of thing you're after?

Chris
# Returning all Host, MAC and Serial details for any NIC with connections
 
$Results = @()
ForEach ($HostName in $Hosts) {
  ForEach ($NIC in $HostName.NICS) {
    ForEach ($Item in $NIC.Items) {
      If ($Item.Connections.Count -gt 0) {
        $Results += "" | Select-Object @{n='Host';e={ $HostName.HostName }}, `
          @{n='MAC';e={ $NIC.MAC }}, @{n='Serial';e={ $NIC.Serial }}
      }
    }
  }
}
$Results
 
# Sample data
 
$Items = @()
$Items += @{
  "mac"=4545645645;
  "serial"=453453453;
  "LocationID"=7;
  "Connections"=@();}
$Items += @{
  "mac"=45645645;
  "serial"=453453453;
  "LocationID"=8;
  "Connections"=@( @{"name"="Connection1"} ); }
 
$NICS = @()
$NICS += @{
  "id"=45345345;
  "local"=0;
  "info"=1;
  "mac"=453453453;
  "items"=$Items;
  "serial"=45345353;}
 
$Items = @()
$Items += @{
  "mac"=4545645622;
  "serial"=453453434;
  "LocationID"=7;
  "Connections"=@( @{"name"="Connection1"}, @{"name"="Connection2"} ); }
$Items += @{
  "mac"=45645623;
  "serial"=453453427;
  "LocationID"=9;
  "Connections"=@();}
 
$NICS += @{
  "id"=4534534873;
  "local"=1;
  "info"=1;
  "mac"=453453453;
  "items"=$Items;
  "serial"=45345353;}
 
$Hosts = @()
$Hosts += @{
  "hostname"="host1";
  "nics"=$NICS}
 
$NICS = @()
$NICS += @{
  "id"=45345332;
  "local"=0;
  "info"=1;
  "mac"=453453453;
  "items"=@();
  "serial"=45345353;}
 
$Hosts += @{
  "hostname"="host2";
  "nics"=$NICS}

Open in new window

0
 
dmc2084Author Commented:
Sorry about all the confusion. I should have started this over from scratch to begin with. I do not think the hashtable script in use was function as intended to begin with.


I am connecting to each host and executing nic software  like so

cat c:\hostlist.txt | (existing script to connect to host and use command line) /e '(cmd (cd c:/)),(cd "Program Files\nic inc "),(cmd /c "ana -rr")' | fl | out-file e:\nicout\nics.txt
This will give a pretty lengthy output and messy too.



The output shows all the hosts first at the top of the file. Then shows the disk info for all of the hosts.

each Target has its own set of luns  you can see examples of target below.



Below is the output when cmd /c "ana -rr" is run from powershell. The output is clean if you were to log into the host open cmd and then run cmd /c "ana -rr"

Powershell output
Host        : host1
IP          : 55151655
Host        : host2
IP          : 55151655
Host        : host3
IP          : 55151655
Host        : host4
IP          : 55151655



this example shows Target 8. After all drives have been Listed then it would start with Target 9 and list all of target 9's drives

  -00 ------------------------------------------------------------------------------ Path                  
                   : 0 Target                     : 8 Device ID                  : Random info            : Random info
              Random info                 : 567               Random info           Random info    
                       : Random info Node Name                  : 434533453 Port Name                  : 00-
              00-11-22-33-44-55-66 Port ID                    : 00 Product Type               : Random info
              N(s)           : 10 Status                     : Online -------------------------------------------------
              ----------------------------- -------------------------------------- lun 0 ------------------------------
              -------- Random info             : Random info                 : Random info      Random info        
                            : dfg-2 dfgffg dfgfd   (e.g., kafnetid fjsu) NICID                      : 00-00
              -11-22-33-44-55-66   -------------------------------------- lun 1 --------------------------------------
              ferdrtf defgrt             : deserser frtrdcrf ID                 : VV               dertfds fedftrd    
                    : 0000 LUN                        : 1 Size                       : 557 Type                  
                   : SBC-2 nmghjm hjghjh block  (Random info ) fsers                      : 44-55-66-77-88
              -55-55-44   -------------------------------------- lun 2 -------------------------------------- trtygfv V
              endor             : fdserdsd drtfrdt dr                 : dd               drtfrtg drtfrtg          : 0
              000 Lun                        : 2 Size                       : 1 hjhu                       : hj
              C-2 dfrtgf dfrss fgtrd device (e.g., fsfgretf fsrt) fsrtf                      : 00-11-22-33-44-55-66-77
                 -------------------------------------- lun 3 -------------------------------------- Product Vendor    
           


If I log into the host itself and run the cli command in cmd it looks great

Below is the output from running cmd /c "ana -rr"  from cmd when loged into the host in question.



Cmd from host output
 
HBA Instance 0: 54554 Port 1 WWPN 55-55-55-55-55-55-55-55 Port ID 55-55-55
------------------------------------------------------------------------------
Path                       : 0
Target                     : 8
Device ID                  : 00
Product Vendor             : 00
Product ID                 : 11              
Product Revision           : 5555
Serial Number              : 111
Node Name                  : 00-11-22-33-44-55-66-77
Port Name                  : 22-33-44-55-66-77-88-99
Port ID                    : 00
Product Type               : Disk
Number of LUN(s)           : 10
Status                     : Online
------------------------------------------------------------------------------
--------------------------------------
LUN 0
--------------------------------------
Product Vendor             : 00
Product ID                 : 11              
Product Revision           : 5555
LUN                        : 0
Size                       : mb
Type                       : direct
WWULN                      : 11-11-11-11-11-11-11-11
 
--------------------------------------
LUN 1
--------------------------------------
Product Vendor             : 00
Product ID                 : 11            
Product Revision           : 5555
LUN                        : 1
Size                       : mb
Type                       : direct
WWULN                      : 22-22-22-22-22-22-22-22
 
--------------------------------------


 To try and explain the target output some more I will make an example. See above how its target lun lun.   The full output looks something like

Target 1
                Lun
                Lun
                Lun
                Lun
Target 2
                Lun
                Lun
Target 3
                 Lun
And so on.

The end result is to be able to connect to a list of hosts. Open cmd and navagate to the program directory and enter in the programs cli command to pull all nic info

Then sort through the output and out file it to a single text file with the output looking like the following.


Hostname  Target  node name                                                port name              lun      wwuln
host1                   8       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    0       11-11-11-11
host1                   8       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    1       22-22-22-22
host1                   9       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    2       33-33-33-33-33
host2                   1       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    1       44-44-44-44-44
-00 ------------------------------------------------------------------------------ Path                  
                   : 0 Target                     : 8 Device ID                  : Random info            : Random info
              Random info                 : 567               Random info           Random info     
                       : Random info Node Name                  : 434533453 Port Name                  : 00-
              00-11-22-33-44-55-66 Port ID                    : 00 Product Type               : Random info
              N(s)           : 10 Status                     : Online -------------------------------------------------
              ----------------------------- -------------------------------------- lun 0 ------------------------------
              -------- Random info             : Random info                 : Random info      Random info         
                            : dfg-2 dfgffg dfgfd   (e.g., kafnetid fjsu) NICID                      : 00-00
              -11-22-33-44-55-66   -------------------------------------- lun 1 -------------------------------------- 
              ferdrtf defgrt             : deserser frtrdcrf ID                 : VV               dertfds fedftrd     
                    : 0000 LUN                        : 1 Size                       : 557 Type                  
                   : SBC-2 nmghjm hjghjh block  (Random info ) fsers                      : 44-55-66-77-88
              -55-55-44   -------------------------------------- lun 2 -------------------------------------- trtygfv V
              endor             : fdserdsd drtfrdt dr                 : dd               drtfrtg drtfrtg          : 0
              000 Lun                        : 2 Size                       : 1 hjhu                       : hj
              C-2 dfrtgf dfrss fgtrd device (e.g., fsfgretf fsrt) fsrtf                      : 00-11-22-33-44-55-66-77
                 -------------------------------------- lun 3 -------------------------------------- Product Vendor    
            
 
 
If I log into the host itself and run the cli command in cmd it looks great
 
Below is the output from running cmd /c "ana -rr"  from cmd when loged into the host in question. 
 
 
 
Cmd from host output
 
HBA Instance 0: 54554 Port 1 WWPN 55-55-55-55-55-55-55-55 Port ID 55-55-55
------------------------------------------------------------------------------
Path                       : 0
Target                     : 8
Device ID                  : 00
Product Vendor             : 00
Product ID                 : 11              
Product Revision           : 5555
Serial Number              : 111
Node Name                  : 00-11-22-33-44-55-66-77
Port Name                  : 22-33-44-55-66-77-88-99
Port ID                    : 00
Product Type               : Disk
Number of LUN(s)           : 10
Status                     : Online
------------------------------------------------------------------------------
--------------------------------------
LUN 0
--------------------------------------
Product Vendor             : 00
Product ID                 : 11              
Product Revision           : 5555
LUN                        : 0
Size                       : mb
Type                       : direct
WWULN                      : 11-11-11-11-11-11-11-11
 
--------------------------------------
LUN 1
--------------------------------------
Product Vendor             : 00
Product ID                 : 11             
Product Revision           : 5555
LUN                        : 1
Size                       : mb
Type                       : direct
WWULN                      : 22-22-22-22-22-22-22-22
 
--------------------------------------
 
 
 
Target 1
                Lun
                Lun
                Lun
                Lun
Target 2
                Lun
                Lun
Target 3
                 Lun
And so on.
 
 
 
 
Hostname  Target  node name                                                port name              lun      wwuln
host1                   8       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    0       11-11-11-11-11-11-11-11
host1                   8       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    1       22-22-22-22-22-22-22-22
host1                   9       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    2       33-33-33-33-33-33-33-33
host2                   1       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    1       44-44-44-44-44-44-44-44

Open in new window

0
 
Chris DentPowerShell DeveloperCommented:

I'd be tempted to drop the Format-List (FL) included above. I'd probably drop cmd /c as well and run the command within the PowerShell shell. Does it return the correct information when run like that?

Chris
0
 
dmc2084Author Commented:
Droping (FL) has the data going to a text file side by side.  Like so

HBA Instance,target, lun, lun, HBA Instance, target,  lun, lun, HBA Instance, target, lun, lun, HBA Instance, target lun lun

Rather than what is was doing

HBA Instance
target
lun
lun
HBA Instance
target
lun
lun

Both ways it is still messy looking with all of the lines ----

With cmd /c removed there was no longer any output
0
 
Chris DentPowerShell DeveloperCommented:

Hmm well either can be cleaned so it doesn't matter much whether we have comma delimited or line delimited if it has to be worked on either way.

For cmd /c.... is it actually executing the command? If you're in the same folder as it you'll want to do "./ana -rr" to run it.

Chris
0
 
dmc2084Author Commented:
cmd /c is executing the command. It will not run without it
0
 
Chris DentPowerShell DeveloperCommented:

cmd /c opens a new command shell, executes the specified command then terminates. The command could be in a batch file, PowerShell has no involvement in it's execution in this scenario.

Chris
0
 
dmc2084Author Commented:
Is there a better way to connect to a remote host vis powershell and use command line that might help in avoiding the use of cmd /c
0
 
Chris DentPowerShell DeveloperCommented:

What are you using to connect to the remove machine now? It doesn't really matter as long as the output from the command ends up in the right file, that's all PowerShell is going to be reading?

We can stick with "cmd /c" if it's working, but I would drop all attempts at formatting it there unless it's making no difference to the returned values.

Chris
0
 
dmc2084Author Commented:
I found if I use cmd /c "ana -rr -o c:\test.txt"  It will send the output to a file on the remote machine into a text file very clean. So I used get-content with powershell to get the content of that text file and it was very clean. But I want to avoid creating files on the remote host.
0
 
Chris DentPowerShell DeveloperCommented:

Even if we delete the text file immediately afterwards? Or can it go onto a network drive?

Chris
0
 
dmc2084Author Commented:
Went onto one of the remote machines in questions and found in powershell I could do the following


cd "Program Files\nic inc"
cmd /c ana -rr

output came out clean

now to figure out how to do this remotely

Once the output is coming in cleaner it would then be possible to take that output that has been exported to a text file and rearrange it to look like the following in the shown order?

I would like to get it in this order at some point so it can be easily inserted into a database

Hostname  Target  node name                                                port name              lun      wwuln
host1                   8       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    0       11-11-11-11
host1                   8       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    1       22-22-22-22
host1                   9       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    2       33-33-33-33-33
host2                   1       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99    1       44-44-44-44-44





Rather than




HBA Instance 0: 54554 Port 1 WWPN 55-55-55-55-55-55-55-55 Port ID 55-55-55
------------------------------------------------------------------------------
Path                       : 0
Target                     : 8
Device ID                  : 00
Product Vendor             : 00
Product ID                 : 11              
Product Revision           : 5555
Serial Number              : 111
Node Name                  : 00-11-22-33-44-55-66-77
Port Name                  : 22-33-44-55-66-77-88-99
Port ID                    : 00
Product Type               : Disk
Number of LUN(s)           : 10
Status                     : Online
------------------------------------------------------------------------------
--------------------------------------
LUN 0
--------------------------------------
Product Vendor             : 00
Product ID                 : 11              
Product Revision           : 5555
LUN                        : 0
Size                       : mb
Type                       : direct
WWULN                      : 11-11-11-11-11-11-11-11
 
--------------------------------------
LUN 1
--------------------------------------
Product Vendor             : 00
Product ID                 : 11            
Product Revision           : 5555
LUN                        : 1
Size                       : mb
Type                       : direct
WWULN                      : 22-22-22-22-22-22-22-22
 
--------------------------------------
0
 
Chris DentPowerShell DeveloperCommented:

Reordering it once we have it in some complete format is no problem :)

How about PsExec?

Chris
0
 
dmc2084Author Commented:
I was able to the output to come clean by doing cd "Program Files\nic inc" | cmd /c "ana -rr"

Now it looks like

HBA Instance 0: 54554 Port 1 WWPN 55-55-55-55-55-55-55-55 Port ID 55-55-55
------------------------------------------------------------------------------
Path                       : 0
Target                     : 8
Device ID                  : 00
Product Vendor             : 00
Product ID                 : 11              
Product Revision           : 5555
Serial Number              : 111
Node Name                  : 00-11-22-33-44-55-66-77
Port Name                  : 22-33-44-55-66-77-88-99
Port ID                    : 00
Product Type               : Disk
Number of LUN(s)           : 10
Status                     : Online
------------------------------------------------------------------------------
--------------------------------------
LUN 0
--------------------------------------
Product Vendor             : 00
Product ID                 : 11              
Product Revision           : 5555
LUN                        : 0
Size                       : mb
Type                       : direct
WWULN                      : 11-11-11-11-11-11-11-11
 
--------------------------------------
LUN 1
--------------------------------------
Product Vendor             : 00
Product ID                 : 11            
Product Revision           : 5555
LUN                        : 1
Size                       : mb
Type                       : direct
WWULN                      : 22-22-22-22-22-22-22-22
 
--------------------------------------



Rather than

  -00 ------------------------------------------------------------------------------ Path                  
                   : 0 Target                     : 8 Device ID                  : Random info            : Random info
              Random info                 : 567               Random info           Random info    
                       : Random info Node Name                  : 434533453 Port Name                  : 00-
              00-11-22-33-44-55-66 Port ID                    : 00 Product Type               : Random info
              N(s)           : 10 Status                     : Online -------------------------------------------------
              ----------------------------- -------------------------------------- lun 0 ------------------------------
              -------- Random info             : Random info                 : Random info      Random info        
                            : dfg-2 dfgffg dfgfd   (e.g., kafnetid fjsu) NICID                      : 00-00
              -11-22-33-44-55-66   -------------------------------------- lun 1 --------------------------------------
              ferdrtf defgrt             : deserser frtrdcrf ID                 : VV               dertfds fedftrd    
                    : 0000 LUN                        : 1 Size                       : 557 Type                  
                   : SBC-2 nmghjm hjghjh block  (Random info ) fsers                      : 44-55-66-77-88
              -55-55-44   -------------------------------------- lun 2 -------------------------------------- trtygfv V
              endor             : fdserdsd drtfrdt dr                 : dd               drtfrtg drtfrtg          : 0
              000 Lun                        : 2 Size                       : 1 hjhu                       : hj
              C-2 dfrtgf dfrss fgtrd device (e.g., fsfgretf fsrt) fsrtf                      : 00-11-22-33-44-55-66-77
                 -------------------------------------- lun 3 -------------------------------------- Product Vendor
0
 
Chris DentPowerShell DeveloperCommented:

Good stuff, I'll get on with breaking that down into the object you're after :)

Chris
0
 
dmc2084Author Commented:
Just to provide more information

I am using powershell to connect to a list of remote hosts and then retrieving the lun information via vender utility and then sending it to a text  
file on the local machine I am running powershell from.

The text file will have all of the Target and lun information for all of the hosts that the script was run against.
The output looks like the following




 
Host        : Host1
IP          : 10.10.10.10
DnsCacheHit : True
Success     : True
ExecTime    : 00
Message     : ------------------------------------------------------------------------------
              Host Name                  : host1
              OS Type                    : Microsoft
              OS Version                 : Service Pack
              SDM API Version            : 44
              ------------------------------------------------------------------------------
              HBA Model 22:
                Port 1 WWPN 22-22-22-22-22-22-22-22 SN 4564564564566 (HBA Instance 0) Online
              HBA Model 22:
                Port 1 WWPN 33-33-33-33-33-33-33-33 SN 4564564564566 (HBA Instance 1) Online
              ------------------------------------------------------------------------------
              Total  HBA(s) : 2
             
              Time and date:            Tue march 20 11:37:32 2040
             
              ------------------------------------------------------------------------------





This output lists targets. If a target has luns they will be shown right after the target is displayed. See how target 7 has no luns but target 8 and  9 do.





------------------------------------------------------------------------------
              HBA Instance 0: QLE2460 Port 1 WWPN 22-22-22-22-22-22-22-22 Port ID 22-22-22
              ------------------------------------------------------------------------------
              Path                       : 0
              Target                     : 7
              Device ID                  : 1122
              Product Vendor             : 1122
              Product ID                 : 44              
              Product Revision           : 1122
              Serial Number              : 1122
              Node Name                  : 11-11-11-11-11-11-11-11
              Port Name                  : 22-22-22-22-22-22-22-22
              Port ID                    : 11-11-11
              Product Type               : Device
              Number of LUN(s)           : 0
              Status                     : Online
              ------------------------------------------------------------------------------
              ------------------------------------------------------------------------------
              HBA Instance 0: QLE2460 Port 1 WWPN 33-33-33-33-33-33-33-33 Port ID 33-3A-33
              ------------------------------------------------------------------------------
              Path                       : 0
              Target                     : 8
              Device ID                  : 1122
              Product Vendor             : 1122
              Product ID                 : 44              
              Product Revision           : 1122
              Serial Number              : 1122
              Node Name                  : 11-11-22-22-22-22-11-1A
              Port Name                  : 11-44-44-44-44-44-44-4A
              Port ID                    : 33-43-33
              Product Type               : Disk
              Number of LUN(s)           : 2
              Status                     : Online
              ------------------------------------------------------------------------------
              --------------------------------------
              LUN 0
              --------------------------------------
              Product Vendor             : 1122
              Product ID                 : 44              
              Product Revision           : 1122
              LUN                        : 0
              Size                       : 1 MB
              Type                       : SBC-2 Direct access block device (e.g., magnetic disk)
              WWULN                      : 11-11-11-22-22-22-22-22
               
              --------------------------------------
              LUN 1
              --------------------------------------
              Product Vendor             : 1122
              Product ID                 : VV              
              Product Revision           : 1122
              LUN                        : 1
              Size                       : 1 GB
              Type                       : SBC-2 Direct access block device (e.g., magnetic disk)
              WWULN                      : 22-22-33-22-44-55-66-55
               
              --------------------------------------
------------------------------------------------------------------------------
              HBA Instance 0: QLE2460 Port 1 WWPN 22-22-22-22-22-22-22-22 Port ID 44-44-44
              ------------------------------------------------------------------------------
              Path                       : 0
              Target                     : 9
              Device ID                  : 44
              Product Vendor             : 44
              Product ID                 : VV              
              Product Revision           : 44
              Serial Number              : 4455
              Node Name                  : 44-44-44-44-44-44-44-44
              Port Name                  : 55-55-55-55-55-55-55-55
              Port ID                    : 11-11-11
              Product Type               : Disk
              Number of LUN(s)           : 1
              Status                     : Online
              ------------------------------------------------------------------------------
              --------------------------------------
              LUN 0
              --------------------------------------
              Product Vendor             : 4455
              Product ID                 : 44            
              Product Revision           : 4444
              LUN                        : 0
              Size                       : 1 MB
              Type                       : SBC-2 Direct access block device (e.g., magnetic disk)
              WWULN                      : 77-77-77-77-77-77-77-77
               
              --------------------------------------


The Target and lun list will continue until the next host is listed.  and then repeat for the next host what is listed above or more if it has more luns/targets



Host        : Host2
IP          : 11.11.11.11
DnsCacheHit : True
Success     : True
ExecTime    : 00
Message     : ------------------------------------------------------------------------------
              Host Name                  : host2
              OS Type                    : Microsoft
              OS Version                 : Service Pack
              SDM API Version            : 00
              ------------------------------------------------------------------------------
              HBA Model 22:
                Port 1 WWPN 22-22-22-22-22-22-22-22 SN 4564564566456 (HBA Instance 0) Online
              HBA Model 22:
                Port 1 WWPN 33-33-33-33-33-33-33-33 SN 4564564564645 (HBA Instance 1) Online
              ------------------------------------------------------------------------------
              Total  HBA(s) : 2
             
              Time and date:            Tue march 20 11:37:32 2040
             
              ------------------------------------------------------------------------------



There will be additional host information listed then Lun and target info





My end goal is to pull only host,target,lun,wwuln,node name,port name info and put it into another text file or just only get that info to begin with.

The final output will be in a table looking like


Hostname   Target    Node name                                  port name                    lun         wwuln
 host1          8       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99     0       11-11-11-11
 host1          8       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99     1       22-22-22-22
 host1          9       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99     2       33-33-33-33-33
 host2          1       00-11-22-33-44-55-66-77     22-33-44-55-66-77-88-99     1       44-44-44-44-44







0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 10
  • 9
Tackle projects and never again get stuck behind a technical roadblock.
Join Now