Get file out from Invoke-Webrequest This topic contains 4 replies, has 2 voices, and was last updated by Stig Sörnsen 6 months, 3 weeks ago.Viewing 5 posts - 1 through 5 (of 5 total)Author PostsMarch 2, 2016 at 3:07 am #35914 Stig SörnsenParticipantHi,I am playing around with Web API and returning octet-stream for file download. I was just wondering if there is no way to get the filestream when saving the 'iwr' in a variable?This works: Invoke-WebRequest $url -ContentType "application/json" -OutFile C:\temp\test.txt But I can't manage to get the file out if I save the 'iwr' in a variable? $request = Invoke-WebRequest $url -ContentType "application/json" Just because I'm curious 🙂March 2, 2016 at 5:24 am #35920 Dave WyattModeratorWhat's in your $request.Content property at that point? JSON text, or something else?March 2, 2016 at 6:05 am #35924 Stig SörnsenParticipantHi Dave,I have a byte array:PS C:\> $req.Content | gm TypeName: System.ByteI have tried to loop through every property/method I could fine.March 2, 2016 at 6:09 am #35925 Dave WyattModeratorThat's perfect. With a byte array, you can write to a file: Set-Content -Path C:\temp\test.txt -Encoding Byte -Value $request.Content March 2, 2016 at 6:15 am #35927 Stig SörnsenParticipant@dave, totally awesome! Couldn't figure out to specify the encoding.Tried this:$req.Content > C:\temp\test.txt but that – ofcourse – just printet out the bytes in plain text.Thanks 🙂Author PostsViewing 5 posts - 1 through 5 (of 5 total)You must be logged in to reply to this topic.