Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8683553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:04:28+00:00 2026-06-12T22:04:28+00:00

When passing a hash table to my PowerShell function, it complains that it receives

  • 0

When passing a hash table to my PowerShell function, it complains that it receives an object.

Function ExtendHash(){
  param(
    [hashtable] $source,
    [hashtable] $extender
  )
  ...
}

And the caller:

$hash1 = @{One = 1; Two = 2}
$hash2 = @{Two = 22; three = 3}
ExtendHash($hash1, $hash2)

Cannot convert the System.Object[] value of type System.Object[] to type System.Collection.Hashtable

So how do I make this work? Suggestions?

Also, am I missing something built-in? I want the same pattern as what JavaScript uses to extend default options (merge and override default values).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:04:29+00:00Added an answer on June 12, 2026 at 10:04 pm

    Do not use parenthesis and commas. This is PowerShell (say, arguments are similar to arguments of commands in CMD). That is, call your function like this:

    ExtendHash $hash1 $hash2
    

    In your case expression ($hash1,$hash2) is an array of two items and you pass this array, one argument, to the function. Such a call fails correctly.


    If you use Set-StrictMode -Version 2 then this “common” mistake is caught by PowerShell:

    The function or command was called as if it were a method. Parameters
    should be separated by spaces. For information about parameters, see
    the about_Parameters Help topic.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a function in Lua that operates on a table, repeatedly adding entries
I am mulling over a best practice for passing hash references for return data
passing post data using cURL requires that the name of the input. However, I
When passing a date from datepicker to sort an excel table, somewhere the format
I am having issues passing a dynamic parameter to a JavaScript function using innerHTML.
I am currently passing in the TinyMCE source as a dependency, and then calling
I understand why passing a null to HashTable.Contains() doesn't work, but I don't understand
I have a delegate that modifies an object. I pass an object to the
I have a function that I want to perform on all the types in
I wrote a simple function to create a hashtable out of an xml-file which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.