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
    • #183387
      Topics: 12
      Replies: 38
      Points: 261
      Helping Hand
      Rank: Contributor

      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
      Topics: 0
      Replies: 24
      Points: 158
      Helping Hand
      Rank: Participant

      Try this:

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

Viewing 1 reply thread
  • The topic ‘How to get a CSV from a website into a variable?’ is closed to new replies.