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.