Skip to content

Writing $null to the output causes Trace-PipelineObject error #561

@AnatoliB

Description

@AnatoliB

When any Function writes $null to the output stream, this causes the following error:

ERROR: Trace-PipelineObject : Cannot bind argument to parameter 'InputObject' because it is null.

The $null value can be hardcoded, returned from a cmdlet or a function, etc. For example, each of the following lines causes this error:

$null
Write-Output $null
Get-Something  # This command returns $null

Workaround

Avoid writing $null to output. If you invoke a command that may return $null, capture the value by assigning it to a variable, or pipe it to Out-Null, for example:

$Result = Do-Something
Get-Something | Out-Null

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions