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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:24:49+00:00 2026-05-13T15:24:49+00:00

I am a Powershell noob and seem to keep getting caught on little weird

  • 0

I am a Powershell noob and seem to keep getting caught on little weird behaviors like this. Here is some test code:

 function EchoReturnTest(){
     echo "afdsfadsf"
     return "blah"
 }

 $variable = EchoReturnTest
 echo ("var: " + $variable)

Running this script generates this as output: “var: afdsfadsf blah”

Why does the function not just return the string “blah”?

  • 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-05-13T15:24:49+00:00Added an answer on May 13, 2026 at 3:24 pm

    First, PowerShell functions return all uncaptured “output”. You can capture output by assigning to a variable and you can ignore output by redirecting to $null e.g.:

    $arrayList.Add("hi") > $null
    

    This would normally output something like 0 (the index where “hi” was added) but because we redirected to $null, the output is disregarded.

    Second, echo is just an alias for “Write-Output” which writes the corresponding object to the output stream. return "blah" is just a convenience which is equivalent to:

    Write-Output "blah"
    return
    

    So your function implementation is equivalent to this:

    function EchoReturnTest(){  
        Write-Output "afdsfadsf"  
        Write-Output "blah"
        return
    }  
    

    If you want to “see” some info on the host console without it being considered part of the “output” of a function then use Write-Host e.g.:

    function EchoReturnTest(){  
        Write-Host "afdsfadsf"  
        return "blah"
    }
    

    Also, if you have no parameters then you don’t need the parens at the end of the function name e.g. function EchoReturnTest { return 'blah' }.

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

Sidebar

Related Questions

PowerShell noob question here. I have groups of servers that are listed in separate
I'm powershell newbie and I have a .csv file like this: Group1; User_A Group1;
This is my powershell code to iniltialize and populate the hash of hash $thash
PowerShell is a weird mix of .bat and .NET. In .bat, you check errorlevel
In PowerShell, how can I test if a variable holds a numeric value? Currently,
Does PowerShell have an equivalent to this command construct from sh (and derivatives): $
Do PowerShell scripts run under Mono? I would like to run them on a
In Powershell I am defining a new PSDrive called test . But when I
I almost have this Powershell script completed but I am stuck at the last
First, yes I am a noob to scripting and powershell as that will become

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.