I have a text file with hundreds of rows. Data fields and values separated by a colon and one empty line separating each data set. It looks something like this...
ico
Try this:
$CurrentElement=[pscustomobject]@{}
#get all rows and add element list when row empty is founded
Get-Content "c:\temp\test.txt" | %{
if ($_ -eq "")
{
$CurrentElement
$CurrentElement=[pscustomobject]@{}
}
else
{
$Row=$_.split(':')
Add-Member -InputObject $CurrentElement -MemberType NoteProperty -Name $Row[0] -Value $Row[1]
}
} | export-csv "c:\temp\result.csv" -notype
$CurrentElement | export-csv "c:\temp\result.csv" -notype -Append