Get file out from Invoke-Webrequest This topic contains 4 replies, has 2 voices, and was last updated by Stig Sörnsen 1 year, 10 months ago. Author Posts March 2, 2016 at 3:07 am #35914 Stig SörnsenParticipant Hi, 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 WyattModerator What's in your $request.Content property at that point? JSON text, or something else? March 2, 2016 at 6:05 am #35924 Stig SörnsenParticipant Hi Dave, I have a byte array: PS C:\> $req.Content | gm TypeName: System.Byte I have tried to loop through every property/method I could fine. March 2, 2016 at 6:09 am #35925 Dave WyattModerator That'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 Posts You must be logged in to reply to this topic.