PowerShell Genie

PowerShell: cannot bind a parameter

Error 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Check argument types, parameter sets and pipeline input when PowerShell cannot bind a parameter.

What it means

PowerShell could not bind an argument to the target command. The value may have an incompatible type, the supplied parameters may belong to different parameter sets, or a parameter name may be ambiguous. Inspect the error record to identify the failing argument.

Likely causes

  • A string was passed where the parameter wants an object, such as a name where an ADUser instance is required
  • Two parameters from mutually exclusive parameter sets were supplied together
  • An incoming pipeline object has no property matching a parameter that accepts ValueFromPipelineByPropertyName
  • An array reached a parameter that accepts only one value
  • A parameter name was abbreviated to a prefix that matches more than one parameter

Check

1PS> $CommandName = 'Get-Service'
2PS> Get-Command $CommandName -Syntax
3PS> Get-Help $CommandName -Full
4PS> $Error[0] | Format-List * -Force

Run these checks before changing anything.

1PS> Get-Service [[-Name] <String[]>] [-DependentServices] [-RequiredServices] [-Include <String[]>] [-Exclude <String[]>] [<CommonParameters>]
2PS>
3PS> Exception : System.Management.Automation.ParameterBindingException
4PS> CategoryInfo : InvalidArgument
5PS> FullyQualifiedErrorId : NamedParameterNotFound

Fix

Reduce the call to a valid minimal set, then add optional arguments one at a time. For pipeline binding, capture the incoming objects and inspect them separately with Get-Member; inserting Get-Member directly before the destination changes the pipeline to member-description objects. Use Trace-Command for binding diagnostics when the minimal case remains unclear.

Verify: Run a valid call and the relevant invalid boundary case. Confirm the intended parameter set and output shape.

Reference

Microsoft Learn: about_parameter_binding

Continue
Genie guidePowerShell: cannot bind a parameter

Check argument types, parameter sets and pipeline input when PowerShell cannot bind a parameter.