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

  • SEARCH
  • Home
  • 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 8809671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:56:05+00:00 2026-06-14T02:56:05+00:00

I ran into a snag when I passed a hash table by reference to

  • 0

I ran into a snag when I passed a hash table by reference to a function for splatting purposes. How can I fix this?

Function AllMyChildren {
    param (
        [ref]$ReferenceToHash
    }
    get-childitem @ReferenceToHash.Value
    #  etc.etc.
}
$MyHash = @{
    'path' = '*'
    'include' = '*.ps1'
    'name' = $null
}
AllMyChildren ([ref]$MyHash)

Result: an error (“Splatted variables cannot be used as part of a property or array expression. Assign the result of the expression to a temporary variable then splat the temporary variable instead.”).

Tried to do this:

$newVariable = $ReferenceToHash.Value
get-childitem @NewVariable

That did work and seemed right per the error message. Is it the preferred syntax in a case like this?

  • 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-14T02:56:06+00:00Added an answer on June 14, 2026 at 2:56 am

    1) Passing hashtables (or any instances of classes, i.e. reference types) with [ref] makes no sense because they are always passed by reference themselves. [ref] is used with value types (scalars and instances of structures).

    2) The splatting operator can be applied to a variable directly, not an expression.

    Thus, in order to resolve the problem simply pass the hashtable in the function as it is:

    Function AllMyChildren {
        param (
            [hashtable]$ReferenceToHash # it is a reference itself
        )
        get-childitem @ReferenceToHash
        #  etc.etc.
    }
    $MyHash = @{
        'path' = '*'
        'include' = '*.ps1'
        'name' = $null
    }
    AllMyChildren $MyHash
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am just getting started with NHaml and ran into a snag. This is
Ran into this error message while trying to select some records off a table.
I'm trying to pass variables using get in php, but ran into a snag.
Ran into an interesting problem with a MySQL table I was building as a
Ran into a strange problem in PHP today and I'm wondering if someone can
After tinkering a bit, I've ran into a small visual snag. For some reason,
I ran into a snag recently. I am writing some unit tests to exercise
I am in the process of learning PHP and I ran into a snag,
Ran into a snag and hoping for some insight here. Overview: Universal app. The
I've kind of ran into an ugly snag. I developed a website for a

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.