Skip to content

Handle empty parameter sets in Sync-Parameter - #136

Open
spyr0-sec wants to merge 2 commits into
AutomatedLab:developfrom
spyr0-sec:fix/sync-parameter-null-params
Open

spyr0-sec wants to merge 2 commits into
AutomatedLab:developfrom
spyr0-sec:fix/sync-parameter-null-params

Conversation

@spyr0-sec

Copy link
Copy Markdown

Summary

Sync-Parameter throws when the bound $Parameters hashtable is empty, or when the target command has no parameters at all. In both cases the .Keys.GetEnumerator() pipelines produce $null, and Compare-Object cannot bind a null -ReferenceObject or -DifferenceObject:

Compare-Object: Cannot bind argument to parameter 'ReferenceObject' because it is null.

This is a common case when a caller passes an empty hashtable, for example when a function collects optional parameters from a variable that ends up empty.

Changes

  • Null key collections are replaced with an empty array before they are compared.
  • Added tests for both cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant