I am extracting CPU properties from my Cisco IMC UCS rack servers, and some rack servers have one, two or four CPUs. My goal is to collect the CPU information and add them to my collection which is exported to CSV. My problem is that the collection should look like this, but it is not resulting this way:
Item 1: CPUID_1, CPUID_2
Item 2: CPUID_1, CPUID_2, CPUID_3, CPUID_4
Item 3: CPUID_1, CPUID_2
Item 4: CPUID_1
So I am trying to write my code so that the properties of the collection change to match the number of CPUs, however I cannot get this to work. My results are:
Item 1: CPUID_$CPUCounter, CPUID_$CPUCounter
Item 2: CPUID_$CPUCounter, CPUID_$CPUCounter, CPUID_$CPUCounter, CPUID_$CPUCounter
Item 3: CPUID_$CPUCounter, CPUID_$CPUCounter
Item 4: CPUID_$CPUCounter
Can you advise how I can create dynamic property headers?
My Code:
$CPUCounter = 1
ForEach ($IMCServerProcessor in $IMCServerProcessors)
{
$Item | Add-Member -type NoteProperty -Name 'CPUID_$CPUCounter' -Value @($IMCServerProcessor.Id)
$Item | Add-Member -type NoteProperty -Name 'CPUModel_$CPUCounter' -Value @($IMCServerProcessor.Model)
$Item | Add-Member -type NoteProperty -Name 'OperState_$CPUCounter' -Value @($IMCServerProcessor.OperState)
$Item | Add-Member -type NoteProperty -Name 'Presence_$CPUCounter' -Value @($IMCServerProcessor.Presence)
$Item | Add-Member -type NoteProperty -Name 'SocketDesignation_$CPUCounter' -Value @($IMCServerProcessor.SocketDesignation)
$Item | Add-Member -type NoteProperty -Name 'CPUVendor_$CPUCounter' -Value @($IMCServerProcessor.Vendor)
$Item | Add-Member -type NoteProperty -Name 'CPUIMC_$CPUCounter' -Value @($IMCServerProcessor.Imc)
$Item | Add-Member -type NoteProperty -Name 'Dn_$CPUCounter' -Value @($IMCServerProcessor.Dn)
$Item | Add-Member -type NoteProperty -Name 'Rn_$CPUCounter' -Value @($IMCServerProcessor.Rn)
$CPUCounter += 1
}