Convert xmlhttp textstream to csv

This topic contains 2 replies, has 1 voice, and was last updated by  David Zemdegs 1 year, 5 months ago.

  • Author
    Posts
  • #36210

    David Zemdegs
    Participant

    I'm rewriting an old vbscript to powershell.
    It uses xmlhttp to get data. It then does some fancy footwork using adodb.stream to convert xmlhttp.responseBody to text and then eventually to csv.
    If I look at $XmlHttp.responsetext it appears to be a text stream in the format of a csv file. Does anyone have any ideas how I can convert this text stream to a csv file please?
    Thanks
    David Z

  • #36213

    David Zemdegs
    Participant

    Found it!

    $XmlHttp.responsetext | out-file D:\scripts\SourceFiles\r.txt
    $csv = import-csv D:\scripts\SourceFiles\r.txt

    Too simple!

  • #36293

    David Zemdegs
    Participant

    Nope the above didn't work exactly
    This is what I needed to do:

    $stream = new-object -com ADODB.Stream
    $stream.open()
    $stream.type = 1 # Binary
    $stream.write($objXmlHttp.responsebody)
    $stream.savetofile($rawfile,2) # 2 = overwrite existing or create new
    $stream.close()
    $stream = $nul
    $hpsd = import-csv $rawfile

You must be logged in to reply to this topic.