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 8817091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:46:02+00:00 2026-06-14T04:46:02+00:00

I have a function to which I pass a hashtable. Within the function I

  • 0

I have a function to which I pass a hashtable. Within the function I want to 1) Display text on-screen via Write-Host; 2) display the contents of the hashtable one time — to provide the usual two-column “Name” / “Value” hashtable display. 3) Have the function return $true or $false.

MyFunction $MyHashTable

Within the function:

param (
    [hashtable]$TheHashTable
)
#  Sundry things here and then:
write-host "Some information to display on-screen`n"
#  and then:
$TheHashTable


The expected result of the latter is something like:

Some information to display on-screen

Name    Value
----    -----
a       b
c       d

And eventually:

return $true #  If what I'm doing worked; otherwise, $false


If I call the function as shown above, I see text displayed via Write-Host on-screen, plus the two-column display of the hashtable’s contents — and the text True or False on-screen, depending on what the function returns.

If I call it this way:

$myResult = MyFunction $MyHashTable

… I capture the return value of the function in $myResult — but the display of the hash table’s content is suppressed. It is also suppressed if I do this:

if ( (MyFunction $MyHashTable) -eq $true ) {
    #   do something
} else {
    #   do something different
}

Is there a way to

  1. Ensure the display of hashtable content, no matter how the function is called;
  2. In any case, suppress the on-screen display of True and False when the Return statement is executed?
  • 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-14T04:46:03+00:00Added an answer on June 14, 2026 at 4:46 am

    Any output generated by your function will be sent down the pipeline. This is exactly what happens when you write:

    $TheHashTable
    

    If you want to write this value to the screen instead of the pipeline you should also use Write-Host like you do earlier in the example like so:

    Write-Host $TheHastTable
    

    However using the code above you will probably get something like the following output:

    PS>$table = @{ "test"="fred";"barney"="wilma"}
    PS> write-host $table
    System.Collections.DictionaryEntry System.Collections.DictionaryEntry
    

    Apparently Write-Host does not apply the formatting you expect, this can be fixed by using Out-String like so:

    PS> $table | Out-String | Write-Host
    

    resulting in:

    Name                           Value
    ----                           -----
    barney                         wilma
    test                           fred
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an overloaded function which I want to pass along wrapped in a
I have a function to which I want to pass a custom jQuery function
I have a function which takes a generic ArrayList<?> as one of the parameters
I have a function which I want to take, as a parameter, a 2D
I have this simple function which I pass in an array of strings: function
I have a function dragging movieClips on the stage which pass over other movieClips
I have a function which receives a filename and a json object to write
I have a function which requires me to pass a UTF-8 string pointed by
I have a function in which I pass a filename followed by several integer
suppose I have a function which accept const reference argument pass, int func(const int

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.