How to get a CSV from a website into a variable?

Welcome Forums General PowerShell Q&A How to get a CSV from a website into a variable?

Viewing 1 reply thread
  • Author
    Posts
    • #183387
      Participant
      Topics: 9
      Replies: 21
      Points: 128
      Rank: Participant

      Specifically, I'm trying to get our Azure Billing Report, which is a CSV file, and then write it to Azure blob storage.
      As I am trying to do this from an Azure function, I don't really have the luxury of writing to a file first AFAIK.

      When I do this, everything is fine, and I get a nice CSV
      Invoke-WebRequest $url -Headers $authHeaders -OutFile Billing.txt

      When I do this, all I get is one big string of text:
      $BlobStorageCSV = Invoke-WebRequest $url -Headers $authHeaders

      My Azure Function would then write it to BlobStorage, but ideally not as one big string, but as a nice CSV...

      I have also tried with Invoke-RestMethod, and specifying CSV as the output format, but no luck there either.
      Also, the first two lines of the file is not in CSV format, which might make it trickier(?)...

    • #183615
      Participant
      Topics: 0
      Replies: 21
      Points: 135
      Helping Hand
      Rank: Participant

      Try this:

      $BlobStorageCSV = Invoke-WebRequest $url -Headers $authHeaders | ConvertTo-Csv

Viewing 1 reply thread
  • You must be logged in to reply to this topic.