Skip to content

Invoke-WebRequest -OutLeaf #20010

@dkaszews

Description

@dkaszews

Summary of the new feature / enhancement

I would like an ability to download a file with Invoke-WebRequest without explicitly providing its name, same as with curl -O. The filename should be deduced from the uri, equivalent to -Uri $Uri -OutFile (Split-Path $Uri). If the uri contains query parameters, they are either discarded (test.txt?param=value results in test.txt), or an error should be given.

Motivating example can be seen in Invoke-WebRequest example #8, the filename is typed twice for every file - once in Uri and once in OutFile.

Additionally, I think that -OutLeaf without -PassThru should return the full resolved path to the downloaded file, so that it can be stored or piped into Start-Process or Invoke-Command for immediate execution (useful for e.g. installers).

Similar proposals were made in:

I agree with the latter, that -OutDirectory could be an alternative API, so that you can get Invoke-WebRequest -OutLeaf with Invoke-WebRequest -OutDirectory ., while also allowing to download files with implicit filename to a different directory.

Opens:

  • Should the filename be url-decoded? I.e. should Invoke-WebRequest example.com/file%20with%space.txt -OutLeaf result in file%20with%20space.txt or file with space.txt? I would say latter, curl says former.

Proposed technical implementation details (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugNeeds-TriageThe issue is new and needs to be triaged by a work group.WG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions