Creating a new PSObject

I’m hoping to get some help with creating a custom object for a reporting script against a NetApp storage cluster. Each storage cluster in my environment contains anywhere from 2 to 12 storage nodes. I’m trying to display relevant settings for each storage node for reporting purposes, but running into format problems that I’m hoping some one can help with. The script looks like the following:

$Inventory = @()

#Gather Data
$ClusterData = Get-NcCluster
$InterfaceData = Get-NcNetInterface
$NodeInfo = Get-NcNode
$PortInfo = Get-NcNetPort

#Display Node Info
        Foreach ($Node in $NodeInfo) {
           $Ports = $PortInfo | where { $_.role -eq "data" -and $_.PortType -eq 'physical' -and $_.LinkStatus -eq 'up' -and $_.Node -eq ($Node.Node) }
           $Inventory += New-Object PSObject -Property @{
                Name = $Node.Node
                Make = $Node.NodeVendor
                Model = $Node.NodeModel
                Serial = $Node.NodeSerialNumber
                SiteID = $SiteCode
                LocationCode = $ClusterData.ClusterLocation
                ClusterMGMT_IP = $ClusterData.NcController.Address.IPAddressToString
                NodeMGMT_IP = ($InterfaceData | Where-Object { $_.role -eq 'node_mgmt' -and $_.HomeNode -eq $Node.Node }).Address
                NodeILO_IP = ($SPInfo| Where-Object { $_.node -eq $Node.Node -and $_.AddressType -eq 'ipv4' }).ipaddress
                Ports = foreach ($Port in $Ports) {
                    New-Object PSObject -Property @{
                        "$Port FlowControl" = $Port.AdministrativeFlowcontrol
                    }
                }
            }
        } 

The above code works fine, but the format is not what I’m looking for. It displays as:
NodeMGMT_IP : 10.22.8.243
Make : NetApp
LocationCode : NYC O8
SiteID : NYC3
ClusterMGMT_IP : 10.22.8.156
Name : NYC3_CUST007_N1632_3B
Model : AFF-A700
Ports : {@{e10a FlowControl=full}, @{e10b FlowControl=full}}
Serial : 782015870374
NodeILO_IP : 10.22.8.245

The problem is the “Ports” item above. I want to make each “Port” a separate line item so that the report looks like:
Port e10a FlowControl: full
Port e10b FlowControl: full

instead of being a single line containing multiple items.

To remediate this, I modified the “Port” section above and tried using the “Add-member” using the following:

foreach ($Port in $Ports) {
                $Inventory | Add-Member -MemberType NoteProperty -Name "$Node.Node Port $Port" -value "$Port.AdministrativeFlowcontrol"
            }`

This seemed to have worked in creating separate line items, but, it unfortunately increments the ports for each additional node that it enumerates, so by the time the 3rd node displays it shows all the ports from node 1 and 2 in its results. I’ve been searching high and low on how to resolve this but can’t seem to find anything. Any help that someone can provide would be immensely appreciated.

You have to make a decission if you want to have structured or hierarchical data. If you want to go the “structured data” approach your desired layout is wrong. You would need to create a complete data set for each existing port.
It would look something like this:

DataSet #1
NodeMGMT_IP     : 10.22.8.243
Make            : NetApp
LocationCode    : NYC O8
SiteID          : NYC3
ClusterMGMT_IP  : 10.22.8.156
Name            : NYC3_CUST007_N1632_3B
Model           : AFF-A700
Ports           : e10a = full
Serial          : 782015870374
NodeILO_IP      : 10.22.8.245

DataSet #2
NodeMGMT_IP     : 10.22.8.243
Make            : NetApp
LocationCode    : NYC O8
SiteID          : NYC3
ClusterMGMT_IP  : 10.22.8.156
Name            : NYC3_CUST007_N1632_3B
Model           : AFF-A700
Ports           : e10b = full
Serial          : 782015870374
NodeILO_IP      : 10.22.8.245

Notice that there is actually only one difference between both data sets. Probably you even could separate the port number/address and the speed (full/half ?).

The other option would be to store the data hierarchical in XML or JSON or YAML for example.

1 Like

Hmmm…I figured this would be a pretty common issue that would have a simple solution.

Unfortunately, using the structured data set in your example will not be very useful for my use case. I have numerous “Storage Node” items that present a similar problem that my “Ports” object poses in my original post. How would I set this up in a Hierarchical structure so that I can report ALL of the Node options as 1 single object. Thanks in advance.

Why not?

What do you want to do with the data you collected?

The simplest case would be to export the original object with the cmdlet

If you need the data for further processing you simply import the data again with

and you can work with the actual original object.

What do you want to do with the data you collected?

The data is being used to audit my storage environments to insure consistency across nodes. I want to create an object for each node and export the settings for easy comparison. I can pull all of the data I need, I just can’t figure out the formatting as discussed in my original post.

Actually you can use the object you created in your initial post.

Will this audit be made by a human being or do you want to use a kind of software? If it is the first one why not using the data just like they are? If you want to uses a software you should use the data format the software needs. If you want to compare different versions from different points in time of the data you could use an XML format I recommended in my last post.

Olaf,

Thank you for all your help. The audit will be done by a human reading through the script results. My original design was to to have each port item listed as a property under the node that it belongs to. Based on our conversation, I now realize that it doesn’t look to be possible. At least the data is there, it’s just displayed as an array of hashes versus an individual line for each port.

Even if it’s possible it is a lot of effort with actually little to no benefit I think.

You may improve readability by concatenating the port names if needed. Instead of …

Ports : {@{e10a FlowControl=full}, @{e10b FlowControl=full}}

… it may look like this then for example …

Ports : e10a, e10a