Ok, so without knowing your input data, here is a skeleton of how you would approach the problem in PowerShell. Remember that in PowerShell you are dealing with objects, which actually makes this a lot easier.
My input data is as shown:
IncidentID,Comment
IT01,"User says stuff is broken"
IT01,"All fixed"
IT02,"Printer is out of toner. Sent Moss to replace."
IT03,"Jen turned off the internet."
IT03,"Douglas is very cross - we need a fix urgently."
IT03,"Turns out Roy was playing a practical joke on Jen."
First, I import the CSV into an array of records - this is basically your 2d array, except that it's actually a 1-dimensional array of objects.
$> $records = Import-CSV myfile.csv
Then, we group the objects by the IncidentID
$> $incidents = $records | Group IncidentID
If we print $incidents now, we can see how that looks:
$> $incidents
Count Name Group
----- ---- -----
2 IT01 {@{IncidentID=IT01; Comment=User says stuff is broken}, @{IncidentID=IT01; Comment=All fixed}}
1 IT02 {@{IncidentID=IT02; Comment=Printer is out of toner. Sent Moss to replace.}}
3 IT03 {@{IncidentID=IT03; Comment=Jen turned off the internet.}, @{IncidentID=IT03; Comment=Douglas is very cros...
To access a single record, you can use the following syntax:
$> $incidents[0].Group[0]
IncidentID Comment
---------- -------
IT01 User says stuff is broken
Finally, to turn the array of comments into a single string, you can use the following, which will create a "Calculated Property" (in PowerShell parlance) called Comments which flattens the comment array into a string.
$> $final = $incidents | `
Select Name, `
@{`
Name='Comments'; `
Expression={ $_.Group | Select -Expand Comment | Out-String }}
$> $final[0].Comments
User says stuff is broken
All fixed
Import-CSVcmdlet for importing into an array of objects. However, I don't really understand how you would import a CSV into a multi-dimensional array (unless you mean a 2-dimensional array, as opposed to a jagged array?). A CSV is inherently a 2-d structure...Import-CSVinto aGroup-By.Group-Object(akaGroup). I've posted an example of how to use bothImport-CSVandGroup-Object. Other useful cmdlets for record processing includeSelect-Object(for projecting out different sorts of objects - maybe you only want the first 3 fields for exampl) andSort-Object(sorts the input by whatever property you specify),