Author Posts

March 7, 2016 at 2:21 pm

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

March 7, 2016 at 2:25 pm

Found it!

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

Too simple!

March 8, 2016 at 2:59 pm

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