Hello,
I’m trying to break the text file shown below into columns and output to .csv.
Name Nodes Requested Protection HDD Total % SSD Total %
----------------------------------------------------------------------------------------
n410_108tb_48gb 1-3 +2d:1n 57.9355T 286.4162T 20.23% 0 0 0.00%
----------------------------------------------------------------------------------------
Total: 1 57.9355T 286.4162T 20.23% 0 0 0.00%
I’m trying to generate csv with the following columns
Name,Nodes,Requested,Protection,HDD,Total,%,SSD,Total,%
n410_108tb_48gb,1-3,+2d:1n,57.9355T,286.4162T,20.23%,0,0,0.00%
Here’s the code I have so far:
Get-Content -Path c:\temp\test.txt | Select-String -Pattern ‘–’, ‘Total:’ -notmatch | Out-File c:\temp\test2.txt
$values = Get-Content -Path c:\temp\test2.txt
$values2 = $values -replace ’ {1,}', “,”
In the above, I’m taking out the lines with dashes and the final line with ‘Total:’ in the substring. This gives me the desired output:
Name,Nodes,Requested,Protection,HDD,Total,%,SSD,Total,%
n410_108tb_48gb,1-3,+2d:1n,57.9355T,286.4162T,20.23%,0,0,0.00%
However, when I write that out as a .csv, it does not break it down into columns as expected.
Thanks.