locked
invoke-webrequest with -outfile and -passthru write empty file RRS feed

  • Question

  • My command

    invoke-restmethod -uri $url  -method get -Headers @{"Authorization"="Basic $apiKey"} -OutFile $outFile

    properly writes the file.  But when I add -passthru it writes a zero-byte file.  What's up with that?


    Leo Tohill

    Wednesday, May 24, 2017 3:23 PM

All replies

  • PassThru is meaningless in this scenario


    \_(ツ)_/

    • Proposed as answer by Hello_2018 Monday, June 5, 2017 2:03 AM
    Wednesday, May 24, 2017 4:03 PM
  • My command

    invoke-restmethod -uri $url  -method get -Headers @{"Authorization"="Basic $apiKey"} -OutFile $outFile

    properly writes the file.  But when I add -passthru it writes a zero-byte file.  What's up with that?


    Leo Tohill

    it works on my machine:

    Invoke-RestMethod -Uri 'https://blogs.msdn.microsoft.com/powershell/feed/' -Method Get -Headers @{"Authorization"="Basic $apiKey"} -PassThru -OutFile d:\22222.txt
    

    -PassThru:

    Indicates that the cmdlet returns the results, in addition to writing them to a file. This parameter is valid only when the OutFile parameter is also used in the command.

    https://msdn.microsoft.com/en-us/powershell/reference/5.1/microsoft.powershell.utility/invoke-restmethod

    PS:

    PS C:\windows\system32> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      5.0.10240.17146
    WSManStackVersion              3.0
    SerializationVersion           1.1.0.1
    CLRVersion                     4.0.30319.42000
    BuildVersion                   10.0.10011.16384
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    PSRemotingProtocolVersion      2.3
    
    

    Best regards,

    Andy


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Thursday, May 25, 2017 8:14 AM
  • Hi,
    Was your issue resolved? 
    If you resolved it using our solution, please "mark it as answer" to help other community members find the helpful reply quickly.
    If you resolve it using your own solution, please share your experience and solution here. It will be very beneficial for other community members who have similar questions.
    If no, please reply and tell us the current situation in order to provide further help.
    Best Regards,
    Andy

    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    Monday, June 5, 2017 2:02 AM