dmc2084
asked on
Need help Manipulating powershell output
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
Is this possible? Anyone know a way?
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
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
Is this possible? Anyone know a way?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I also run into New-Object : Cannot find type [PSCustomObject]: make sure the assembly containing this type is loaded.
Ahh, sorry, I wrote this in PowerShell v2.. change PSCustomObject to PSObject and it should run.
ASKER
Made the change to PSObject and its working good so far, doing a little more testing.
Thank you so very much. I will replay today with the results.
Thank you so very much. I will replay today with the results.
ASKER
What would be the best way to output to a file comma separated from $results | ft Hostname, Target, NodeName, PortName, WWULN?
ASKER
Figured it out
did $results | select-object hostname,target | export-csv
did $results | select-object hostname,target | export-csv
ASKER
Trying get-content c:\test.txt as my command and getting
Method invocation failed because [System.Object[]] doesn't contain a method named 'Split'.At c:\test.txt