Skip to content

Invoke-WebRequest -OutLeaf #20010

Open
Open

Description

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

Activity

  1. CarloToso commented on Jul 22, 2023

    @CarloToso
    Contributor

    Similar to #11671, partially addressed by #19007 and #19385

  2. dkaszews commented on Jul 22, 2023

    @dkaszews
    ContributorAuthor

    Does #19007 mean you can just specify a directory with -OutFile and it will just work as I described? I did not see anything about it in documentation.

  3. CarloToso commented on Jul 22, 2023

    @CarloToso
    Contributor

    Yes, but it's still being worked on so it could not work as expected in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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