Powershell and CSV Problems
hello been write lot of new functions lately need write output csv file , can't out-put right been looking around lot on internet non of examples have found dose need. here code
$numcolstoexport = "4" $content= @("1", "2", "3","4", "5", "6", "7") $finalhash=@() $headers=@("namn","status","net","ram","test", "test","test") foreach ($row in $content){ $obj = new-object psobject ($i=0;$i -lt $numcolstoexport; $i++){ $obj | add-member -membertype noteproperty -name $headers[$i] -value $row[$i] } $finalhash+=$obj $obj=$null } $finalhash | export-csv -path c:\users\sebbe\desktop\test2.csv -notypeinformation
the code generate csv can't $content displayes right. in content placed on separated rows reason. if add row
$content= @("1", "2", "3","4", "5", "6", "7"), ("1", "2", "3","4", "5", "6", "7")
the content looks alright.
any tips?
here starter.
function addarray{ param( $anarray=@(1,2,3,4,5,6,7) ) [pscustomobject]@{ name=$anarray[0] status= $anarray[1] net= $anarray[2] ram= $anarray[3] test1= $anarray[4] test2= $anarray[5] test3= $anarray[6] } } addarray @(1, 2, 3, 4, 5, 6, 7) | export-csv -path c:\users\sebbe\desktop\test2.csv -notypeinformationneed think through requirements , determine asking about. ask useful for. in object systems we do not use arrays much. try thinking in objects.
\_(ツ)_/
Windows Server > Windows PowerShell
Comments
Post a Comment