CSV output is not in specific columns

Welcome Forums General PowerShell Q&A CSV output is not in specific columns

Viewing 4 reply threads
  • Author
    Posts
    • #239633
      Participant
      Topics: 20
      Replies: 30
      Points: 91
      Rank: Member

      Hi,

      Script below, I need some help because the output to CSV is not clean, meaning I want the EID’s to be in one column and the vendorname to be in the column next to EID. Thanks!

      $obj = @()

      $s = NETAssignmentsModified

      $s | ConvertTo-Json

      Foreach($_ in $s){

      }

      $obj += [PSCustomObject]@{
      #breakout all the essential object items
      EID = $_.specialbill.id -as [String]
      Vendor = $_.vendorName -as [String]

      }

      $obj|export-csv -path “c:\users\bwiley\MyData$((Get-Date).ToString(“MMddyyyy”)).csv” -NoTypeInformation

      • This topic was modified 2 months, 3 weeks ago by Jason Colotario. Reason: Selected all text -> Format -> Blocks -> Preformatted
    • #239666
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      When you post code, error messages, sample data or console output format it as code, please.
      In the “Text” view you can use the code tags “PRE“, in the “Visual” view you can use the format template “Preformatted“. You can go back edit your post and fix the formatting – you don’t have to create a new one.
      Thanks in advance.

      What is “NETAssignmentsModified“? Is it a string? What result would you expect when you convert a string into JSON? You should not use $_ as a variable for yourself. It’s the pipeline variable and should not be used for something else. If you had saved a collection you could iterate over in a variable named $s your code could look like this:

    • #239672
      Participant
      Topics: 20
      Replies: 30
      Points: 91
      Rank: Member
    • #239732
      Participant
      Topics: 7
      Replies: 2458
      Points: 6,439
      Helping Hand
      Rank: Community MVP

      So it’s obviously NOT working. ūüėȬ†¬† …. again …. what is “NETAssignmentsModified”??

    • #239918
      Participant
      Topics: 20
      Replies: 30
      Points: 91
      Rank: Member
Viewing 4 reply threads
  • You must be logged in to reply to this topic.