0

I have a PS object with name, column2, column3, etc. I have 3 names and values in each of the columns for those names. I want to loop through and put into a table name1, column1, name2, column1, name3, column1, name1, column2, name2, column2, name3, column2, name1, column3, name2, column3, name3, column3, etc. is there a way to do this?

I have tried and object for names and one for columns and using a for each loop. I'm trying to automate lines of code instead of using a select object to select each name and column.

current code:

    $obj | sort-object Name | Select-object AER, DER, APRO,FPCT
    
    New-HTML {
        New-HTMLSection -Invisible {
            New-HTMLSection {
                New-HTMLTable -DataTable $obj -includeproperty Name, AER -DefaultSortOrder Descending -PagingLength 10 
            }
    New-HTMLSection {
                New-HTMLTable -DataTable $obj -includeproperty Name, DER -DefaultSortOrder Descending -PagingLength 10 
            }
    New-HTMLSection {
                New-HTMLTable -DataTable $obj -includeproperty Name, APRO -DefaultSortOrder Descending -PagingLength 10 
            }
    New-HTMLSection {
                New-HTMLTable -DataTable $obj -includeproperty Name, FPCT -DefaultSortOrder Descending -PagingLength 10 
            }
    }
    
Was looking to do something like this:
    New-HTML {
        New-HTMLSection {
            $Machines = @(
                'Machine1', 'Machine2', 'Machine3'
            )
            foreach ($Machine in $Machines) {
                New-HTMLSection -HeaderText $Machine {
                    $Information = @(
                        'First Information', '2nd Information', '3rd information'
                    )
                    foreach ($I in $Information) {
                        New-HTMLSection -HeaderText $I {
                            New-HTMLTable -DataTable $Machine
                        }
                    }
                } -Direction column
            }
        } -HeaderText "Citrix Machine Information" -Direction column
    } -Online -ShowHTML

current and desired output:

enter image description here

8
  • 1
    1 property = 1 table column. So if you want a table with 9 columns => create an object with 9 properties Commented Feb 15, 2023 at 16:47
  • It is a little unclear what you are asking. Are you saying that you want each property name from your object to become a column in a table, and that the value of the property should become the column value? Or are you saying that each property contains multiple values which need to be split into different columns? Or both? Commented Feb 15, 2023 at 16:59
  • so already have the object with those columns. instead of doing a $obj | select name, column1, $obj | select name, column2, $obj | select name, column3, etc. I would like to loop/iterate through the object, and add html code around it. <Html> name1, column1 <html>,<Html> name2, column1 <html>,<Html> name3, column1 <html>. etc Commented Feb 15, 2023 at 17:18
  • So you want a new row consisting of Name,<Property>, per property (excluding the name)? Commented Feb 15, 2023 at 17:21
  • Use Sort-Object or Group-Object Commented Feb 15, 2023 at 17:23

1 Answer 1

0

I was able to figure this out -thanks everyone.

 New-HTML {
        New-HTMLSection {
            $Machines = @(
                'G','PA','AB','R','H','2B','3B','HR','RBI','SB','CS','BB','SO','TB','GDP','HBP','SH','SF','IBB'
            )
            foreach ($Machine in $Machines) {
                 New-HTMLTable -DataTable $tobj -IncludeProperty  Name,$Machine
            }
        } -HeaderText "Citrix Machine Information" -Direction column
    } -Online -ShowHTML
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.