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 -notypeinformation  
need 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

Popular posts from this blog

CRL Revocation always failed

Failed to query the results of bpa xpath

0x300000d errors in Microsoft Remote Desktop client