Feb 22 2023 11:34 AM
Feb 24 2023 03:38 AM - edited Feb 24 2023 03:29 PM
Hello @tcboeira,
I am sure there are more concise and elegant ways to do it, but here is one of the options that also works:
$Data=Import-Csv 'C:\input.csv'
$ColumnName="E"
$Result=New-Object System.Collections.Generic.List[PsObject]
foreach($l in $data){
$Items=$l.$ColumnName -split ' '
$l.psobject.Properties.Remove($ColumnName)
foreach($i in $Items){
$ht=[ordered]@{}
$l.psobject.properties | Foreach { $ht[$_.Name] = $_.Value }
$ht=$ht+@{$ColumnName=$i}
$Result.Add($(New-Object -TypeName psobject -Property $ht))
$l.psobject.Properties.Remove($ColumnName)
}
}
$Result
Hope that helps.
Feb 28 2023 04:47 AM
Hello,
First of all, thanks for the reply and sorry for the delay in getting back to you...
I think I failed to exemplify correctly...
I extract some data, via CSV file, which returns me like this:
COL1 | COL2 | COL3 | COL4 |
11 | 12 | 13 | 14 |
22 | 22 | 23 24 25 26 | 27 |
33 | 32 | 33 | 34 |
And I wish it could look like this:
COL1 | COL2 | COL3 | COL4 |
11 | 12 | 13 | 14 |
22 | 22 | 23 | 27 |
22 | 22 | 24 | 27 |
22 | 22 | 25 | 27 |
22 | 22 | 26 | 27 |
33 | 32 | 33 | 34 |
I even tried something using the example...
Is that right? Is it for this purpose?
Mar 01 2023 06:56 AM
Hello @tcboeira,
Yes, the code provided is exactly for the use case that you are describing.
Here is the execution of it on your data set:
One caveat is that the order of the columns will be messed up. Column in question will be all the way in the end.
Hope that helps.