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.