Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

7.4.0 Breaking change: Passing -OutFile $null to Invoke-WebRequest fails #20744

Copy link
Copy link
@nowakca

Description

@nowakca
Issue body actions

Prerequisites

Steps to reproduce

Minimal version

Invoke-WebRequest "http://www.microsoft.com" -OutFile $null

Version that is more closely related to how that sneaks in as a surprise script breaker

function DoTheThing($file) {
  $Params=@{
    Uri="http://www.microsoft.com"
    OutFile=$file
    }
  Invoke-WebRequest @Params
}

DoTheThing

Expected behavior

Should return the results of the web call to the output stream

Actual behavior

Invoke-WebRequest: Cannot validate argument on parameter 'OutFile'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

(Works correctly in 7.2.17 and 7.3.3)



### Error details

```console
Exception             : 
    Type              : System.Management.Automation.ParameterBindingValidationException
    Message           : Cannot validate argument on parameter 'OutFile'. The argument is null or empty. Provide an argument that is not null or empty, and then try t
he command again.
    ParameterName     : OutFile
    ParameterType     : string
    ErrorId           : ParameterArgumentValidationError
    Line              : 1
    Offset            : 46
    CommandInvocation : 
        MyCommand        : Invoke-WebRequest
        ScriptLineNumber : 1
        OffsetInLine     : 1
        HistoryId        : 35
        Line             : Invoke-WebRequest "http://www.microsoft.com" @h
        Statement        : Invoke-WebRequest "http://www.microsoft.com" @h
        PositionMessage  : At line:1 char:1
                           + Invoke-WebRequest "http://www.microsoft.com" @h
                           + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        InvocationName   : Invoke-WebRequest
        PipelineLength   : 1
        PipelinePosition : 1
    ErrorRecord       : 
        Exception             : 
            Type    : System.Management.Automation.ParentContainsErrorRecordException
            Message : Cannot validate argument on parameter 'OutFile'. The argument is null or empty. Provide an argument that is not null or empty, and then try the
 command again.
            HResult : -2146233087
        CategoryInfo          : InvalidData: (:) [Invoke-WebRequest], ParentContainsErrorRecordException
        FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
        InvocationInfo        : 
            MyCommand        : Invoke-WebRequest
            ScriptLineNumber : 1
            OffsetInLine     : 46
            HistoryId        : 35
            Line             : Invoke-WebRequest "http://www.microsoft.com" @h
            Statement        : @h
            PositionMessage  : At line:1 char:46
                               + Invoke-WebRequest "http://www.microsoft.com" @h
                               +                                              ~~
            CommandOrigin    : Internal
        ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1
    TargetSite        : 
        Name          : BindParameter
        DeclaringType : System.Management.Automation.ParameterBinderBase, System.Management.Automation, Version=7.4.0.500, Culture=neutral, PublicKeyToken=31bf3856ad
364e35
        MemberType    : Method
        Module        : System.Management.Automation.dll
    Data              : System.Collections.ListDictionaryInternal
    InnerException    : 
        Type        : System.Management.Automation.ValidationMetadataException
        ErrorRecord : 
            Exception             : 
                Type    : System.Management.Automation.ParentContainsErrorRecordException
                Message : The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
                HResult : -2146233087
            CategoryInfo          : MetadataError: (:) [], ParentContainsErrorRecordException
            FullyQualifiedErrorId : ArgumentIsNull
        TargetSite  : 
            Name          : Validate
            DeclaringType : System.Management.Automation.ValidateNotNullOrAttributeBase
            MemberType    : Method
            Module        : System.Management.Automation.dll
        Message     : The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
        Source      : System.Management.Automation
        HResult     : -2146233087
        StackTrace  : 
   at System.Management.Automation.ValidateNotNullOrAttributeBase.Validate(Object arguments, EngineIntrinsics engineIntrinsics)
   at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBinding
Flags flags)
    Source            : System.Management.Automation
    HResult           : -2146233087
    StackTrace        : 
   at System.Management.Automation.ParameterBinderBase.BindParameter(CommandParameterInternal parameter, CompiledCommandParameter parameterMetadata, ParameterBinding
Flags flags)
   at System.Management.Automation.CmdletParameterBinderController.BindParameter(CommandParameterInternal argument, MergedCompiledCommandParameter parameter, Paramet
erBindingFlags flags)
   at System.Management.Automation.CmdletParameterBinderController.BindParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandParame
ter parameter, ParameterBindingFlags flags)
   at System.Management.Automation.CmdletParameterBinderController.BindNamedParameter(UInt32 parameterSets, CommandParameterInternal argument, MergedCompiledCommandP
arameter parameter)
   at System.Management.Automation.ParameterBinderController.BindNamedParameters(UInt32 parameterSets, Collection`1 arguments)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParametersNoValidation(Collection`1 arguments)
   at System.Management.Automation.CmdletParameterBinderController.BindCommandLineParameters(Collection`1 arguments)
   at System.Management.Automation.CommandProcessor.BindCommandLineParameters()
   at System.Management.Automation.CommandProcessor.Prepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.CommandProcessorBase.DoPrepare(IDictionary psDefaultParameterValues)
   at System.Management.Automation.Internal.PipelineProcessor.Start(Boolean incomingStream)
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
--- End of stack trace from previous location ---
   at System.Management.Automation.Internal.PipelineProcessor.SynchronousExecuteEnumerate(Object input)
   at System.Management.Automation.PipelineOps.InvokePipeline(Object input, Boolean ignoreInput, CommandParameterInternal[][] pipeElements, CommandBaseAst[] pipeElem
entAsts, CommandRedirection[][] commandRedirections, FunctionContext funcContext)
   at System.Management.Automation.Interpreter.ActionCallInstruction`6.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
CategoryInfo          : InvalidData: (:) [Invoke-WebRequest], ParameterBindingValidationException
FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
InvocationInfo        : 
    MyCommand        : Invoke-WebRequest
    ScriptLineNumber : 1
    OffsetInLine     : 46
    HistoryId        : 35
    Line             : Invoke-WebRequest "http://www.microsoft.com" @h
    Statement        : @h
    PositionMessage  : At line:1 char:46
                       + Invoke-WebRequest "http://www.microsoft.com" @h
                       +                                              ~~
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 1

Environment data

Name                           Value
----                           -----
PSVersion                      7.4.0
PSEdition                      Core
GitCommitId                    7.4.0
OS                             Red Hat Enterprise Linux 8.8 (Ootpa)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No really necessary, literally just paste Invoke-WebRequest "http://www.microsoft.com" -OutFile $null into a shell and watch the error show up

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.WG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility modulecmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.