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 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?
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.type = 1 # Binary
$stream.savetofile($rawfile,2) # 2 = overwrite existing or create new
$stream = $nul
$hpsd = import-csv $rawfile