Bad issue not fixed in PowerShell 7.6-preview.6 #26853
adam-kami-1
started this conversation in
General
Replies: 2 comments
-
|
I expect this is by design. If you want to allow empty strings add the |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thank you very much. That helped. But I would rather expect the opposite behavior as the default. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I found problem in PowerShell 7.5.4. After installing 7.6 preview the problem still exists.
Short: PowerShell does not accept empty string as a parameter value, direct or piped ByValue. The problem happens with simple [string] or array of strings [string[]]. The reported error is Cannot bind argument to parameter 'InputObject' because it is an empty string.
As result you cannot e.g. pipe output from Get-Content to any script when piped file contains ampty lines.
Very bad workaround for the problem is to declare parameter as [System.Object] and retyping it as a [System.string] inside but this will not work when you want to check/recognize type of piped ByValue objects.
The script to test this issue looks like below:
The output of above script run with parameter verbose looks like below:
`
19.02.2026 12:31:58
adamm@SURFACE[PS(1)]:M:\Users\Adam\PRJs\PowerShell
$ .\Test-Param.ps1 -verbose
VERBOSE: StringArray: Entering Begin block, $InputObject is string[] = abc def gh
VERBOSE: StringArray: Entering Process block, $InputObject is string[] = abc def gh
VERBOSE: StringArray: Entering End block, $InputObject is string[] = abc def gh
VERBOSE:
VERBOSE: StringArray: Entering Begin block, $InputObject is string[] = abc def gh
VERBOSE: StringArray: Entering Process block, $InputObject is string[] = abc def gh
VERBOSE: StringArray: Entering End block, $InputObject is string[] = abc def gh
VERBOSE:
VERBOSE: StringArray: Entering Begin block, $InputObject is $null
VERBOSE: StringArray: Entering Process block, $InputObject is string[] = abc
VERBOSE: StringArray: Entering Process block, $InputObject is string[] = def
VERBOSE: StringArray: Entering Process block, $InputObject is string[] = gh
VERBOSE: StringArray: Entering End block, $InputObject is string[] = gh
VERBOSE:
StringArray: M:\Users\Adam\PRJs\PowerShell\Test-Param.ps1:75
Line |
75 | StringArray -InputObject 'abc', '', 'gh'
| ~~~~~~~~~~~~~~~
| Cannot bind argument to parameter 'InputObject' because it is an empty string.
VERBOSE: StringArray: Entering Begin block, $InputObject is $null
VERBOSE: StringArray: Entering Process block, $InputObject is string[] = abc
StringArray: M:\Users\Adam\PRJs\PowerShell\Test-Param.ps1:76
Line |
76 | 'abc', '', 'gh' | StringArray
| ~~~~~~~~~~~
| Cannot bind argument to parameter 'InputObject' because it is an empty string.
VERBOSE: StringArray: Entering Process block, $InputObject is string[] = gh
VERBOSE: StringArray: Entering End block, $InputObject is string[] = gh
VERBOSE:
VERBOSE: SimpleString: Entering Begin block, $InputObject is string = abc
VERBOSE: SimpleString: Entering Process block, $InputObject is string = abc
VERBOSE: SimpleString: Entering End block, $InputObject is string = abc
VERBOSE:
VERBOSE: SimpleString: Entering Begin block, $InputObject is string = abc
VERBOSE: SimpleString: Entering Process block, $InputObject is string = abc
VERBOSE: SimpleString: Entering End block, $InputObject is string = abc
VERBOSE:
VERBOSE: SimpleString: Entering Begin block, $InputObject is string =
VERBOSE: SimpleString: Entering Process block, $InputObject is string = abc
VERBOSE: SimpleString: Entering End block, $InputObject is string = abc
VERBOSE:
SimpleString: M:\Users\Adam\PRJs\PowerShell\Test-Param.ps1:81
Line |
81 | SimpleString -InputObject ''
| ~~
| Cannot bind argument to parameter 'InputObject' because it is an empty string.
VERBOSE: SimpleString: Entering Begin block, $InputObject is string =
SimpleString: M:\Users\Adam\PRJs\PowerShell\Test-Param.ps1:82
Line |
82 | '' | SimpleString
| ~~~~~~~~~~~~
| Cannot bind argument to parameter 'InputObject' because it is an empty string.
VERBOSE: SimpleString: Entering End block, $InputObject is string =
VERBOSE:
Name Value
PSVersion 7.6.0-preview.6
PSEdition Core
GitCommitId 7.6.0-preview.6
OS Microsoft Windows 10.0.26100
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.4
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
`
Beta Was this translation helpful? Give feedback.
All reactions