Skip to content

Invoke-WebRequest / Invoke-RestMethod -Verbose shows only the directory (folder) name when a directory path is passed to -OutFile #21081

@mklement0

Description

@mklement0

Prerequisites

Steps to reproduce

Thanks to a contribution by @CarloToso, since v7.4.0 it has been possible to pass a directory rather than a file path to -OutFile, in which the web cmdlets use the (ultimate) target URL's last segment as the file name.

Given that, when redirections are involved, you won't know what that last segment is, using -Verbose is an important way to discover the effective output file name.

Unfortunately, -Verbose currently misreports the directory's name as the output file name:

# This downloads to file /tmp/ascii_to_unicode.bat
Invoke-WebRequest -Verbose -OutFile /tmp https://filesamples.com/samples/code/bat/ascii_to_unicode.bat

# Clean up
Remove-Item /tmp/ascii_to_unicode.bat

Expected behavior

VERBOSE: Requested HTTP/1.1 GET with 0-byte payload
VERBOSE: Received HTTP/1.1 response of content type application/octet-stream of unknown size
VERBOSE: File Name: ascii_to_unicode.bat

Actual behavior

VERBOSE: Requested HTTP/1.1 GET with 0-byte payload
VERBOSE: Received HTTP/1.1 response of content type application/octet-stream of unknown size
VERBOSE: File Name: tmp

That is, the directory's name is reported.

Error details

No response

Environment data

PowerShell 7.4.0-rc.1

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIndicates that a PR is out for the issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions