Skip to content

Invoke-RestMethod parameter combination of OutFile/PassThru does not write to file as intended #15409

@sdwheeler

Description

@sdwheeler

Problem description

In Invoke-RestMethod, the PassThru parameter must be used with the OutFile parameter. The intent is that you can write the results to the file and get the output to the pipeline. But the cmdlets only write to the pipeline, not the file.

The problem code starts here:

if (ShouldWriteToPipeline)
{
   ...
}
else if (ShouldSaveToOutFile)
{
   ...
}

Notice that the logic outputs pipeline and skips the output to the file. Both ShouldWriteToPipeline and ShouldSaveToOutFile can be true so need to remove the else.

Steps to reproduce

Invoke-RestMethod https://taxonomyservice.azurefd.net/taxonomies/product-uri -PassThru -OutFile C:\temp\irm.json

Expected behavior

Output to console and to the file.

Actual behavior

Output to console only. The output file is not created.

Environment data

This affects all versions 5.1 and higher.

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issueIssue-BugIssue has been identified as a bug in the productUp-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions