PowerShell has really wacky return semantics - at least when viewed from a more traditional programming perspective. There are two main ideas to wrap your head around:

  • All output is captured, and returned
  • The return keyword really just indicates a logical exit point

Thus, the following two script blocks will do effectively the exact same thing:

Copy$a = "Hello, World"
return $a

 

Copy$a = "Hello, World"
$a
return

The $a variable in the second example is left as output on the pipeline and, as mentioned, all output is returned. In fact, in the second example you could omit the return entirely and you would get the same behavior (the return would be implied as the function naturally completes and exits).

Without more of your function definition I can't say why you are getting a PSMethod object. My guess is that you probably have something a few lines up that is not being captured and is being placed on the output pipeline.

It is also worth noting that you probably don't need those semicolons - unless you are nesting multiple expressions on a single line.

You can read more about the return semantics on the about_Return page on TechNet, or by invoking the help return command from PowerShell itself.

Answer from Goyuix on Stack Overflow
Top answer
1 of 10
358

PowerShell has really wacky return semantics - at least when viewed from a more traditional programming perspective. There are two main ideas to wrap your head around:

  • All output is captured, and returned
  • The return keyword really just indicates a logical exit point

Thus, the following two script blocks will do effectively the exact same thing:

Copy$a = "Hello, World"
return $a

 

Copy$a = "Hello, World"
$a
return

The $a variable in the second example is left as output on the pipeline and, as mentioned, all output is returned. In fact, in the second example you could omit the return entirely and you would get the same behavior (the return would be implied as the function naturally completes and exits).

Without more of your function definition I can't say why you are getting a PSMethod object. My guess is that you probably have something a few lines up that is not being captured and is being placed on the output pipeline.

It is also worth noting that you probably don't need those semicolons - unless you are nesting multiple expressions on a single line.

You can read more about the return semantics on the about_Return page on TechNet, or by invoking the help return command from PowerShell itself.

2 of 10
77

This part of PowerShell is probably the most stupid aspect. Any extraneous output generated during a function will pollute the result. Sometimes there isn't any output, and then under some conditions there is some other unplanned output, in addition to your planned return value.

So, I remove the assignment from the original function call, so the output ends up on the screen, and then step through until something I didn't plan for pops out in the debugger window (using the PowerShell ISE).

Even things like reserving variables in outer scopes cause output, like [boolean]$isEnabled which will annoyingly spit a False out unless you make it [boolean]$isEnabled = $false.

Another good one is $someCollection.Add("thing") which spits out the new collection count.

🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_return
about_Return - PowerShell | Microsoft Learn
January 18, 2026 - $Value += 73 return $Value } $a = Calculation 14 · The "Please wait. Working on calculation..." string is not displayed. Instead, it is assigned to the $a variable, as in the following example: PS> $a Please wait. Working on calculation... 87 · Both the informational string and the result of the calculation are returned by the function and assigned to the $a variable. If you would like to display a message within your function, beginning in PowerShell 5.0, you can use the Information stream.
Discussions

Why not use the return statement?
First off I do want to say that you are not in the wrong here. You are using it for the right reasons. The recomendation from me would be to use Write-Output instead unless the situation specifically needs a return statement. That is more what the common convention is. All the reasons you state also apply to Write-Output. Not dropping objects on the pipe and making your intentions clear are exactly the things you should be thinking about. I beleive the reason we are pushed to use Write-Output is so that we are more aware of how we can use the pipe. I step back on all my functions and consider how it works with a set of data and not just a single object (even if the purpose at the time is for single object processing). Because of that, it is very rare that I ever use a return statment. You will walk away with some really great tools that may not show their value until much later More on reddit.com
🌐 r/PowerShell
13
12
May 18, 2016
Explaining Rationale for Function Output Behavior
Ok, so I discovered (the hard way) how functions sort of queue up any output from within the function and then return all of it as part of the return object. function foo () { echo "SettingVar" $var = "varValue" e… More on forums.powershell.org
🌐 forums.powershell.org
8
0
October 3, 2016
newbie question on function return values
All, trying to develop a simple function that does an evaluation and returns $true or $false, but the result always returns $false. What’s up with that? Am I doing something stupid here? The code works outside of the function. $var = 'VDI' function is_billable([String]$cb) { $list = ... More on forums.powershell.org
🌐 forums.powershell.org
2
0
January 24, 2018
[V1.2] Blueprint Roblox Editor : Visual programming tools for Luau - Community Resources - Developer Forum | Roblox
BlueprintRobloxEditor BRE (Blueprint Roblox Editor) is a blueprint editor for creating Roblox games using a plugin within Roblox Studio. The project uses Rojo, a VS Code extension for managing Roblox projects. DevForum post: [V1.2] Blueprint Roblox Editor : Visual programming tools for Luau ... More on devforum.roblox.com
🌐 devforum.roblox.com
11
November 9, 2025
🌐
Reddit
reddit.com › r/powershell › why not use the return statement?
r/PowerShell on Reddit: Why not use the return statement?
May 18, 2016 -

Coming from a managed code background, I use return in just about every function I write. When I want to return a collection to the pipeline, I add a # return comment so I know that I explicitly meant to return the object. For the community and my coworkers... I am on the wrong side of this battle. I'll continually receive code reviews saying I should not use the return statement, but I think thats their choice. I use it for the purpose of being explicit. I've helped the same people who want me to stop using it debug their broken code because they accidentally were returning something else into their pipeline that they didn't want there. Not just once, but at least once a sprint. Each.

So, grand PowerShell community, what's up with the pushback on return?

Top answer
1 of 5
7
First off I do want to say that you are not in the wrong here. You are using it for the right reasons. The recomendation from me would be to use Write-Output instead unless the situation specifically needs a return statement. That is more what the common convention is. All the reasons you state also apply to Write-Output. Not dropping objects on the pipe and making your intentions clear are exactly the things you should be thinking about. I beleive the reason we are pushed to use Write-Output is so that we are more aware of how we can use the pipe. I step back on all my functions and consider how it works with a set of data and not just a single object (even if the purpose at the time is for single object processing). Because of that, it is very rare that I ever use a return statment. You will walk away with some really great tools that may not show their value until much later
2 of 5
3
I've helped the same people who want me to stop using it debug their broken code because they accidentally were returning something else into their pipeline that they didn't want there. How does the return statement help here? Just because you use "return" doesn't make everything else you output to the pipeline not get outputted. "return" with a parameter doesn't make any sense in PowerShell, and allowing it was a mistake IMO (on the other hand "return" without a parameter, for returning from a function early, is perfectly fine). PowerShell functions don't return values at the end of functions' execution, they write any number of values to the pipeline, and can do so at any point during the execution of a function. This is hugely different to other imperative languages, and those languages use the return $value syntax or similar. In PowerShell, return $value actually means $value; return (or Write-Output $value; return), but it looks very similar to returning a single value in those other, common imperative languages, and thus has high potential for causing confusion and misunderstanding of how PowerShell works with object streams and the pipeline.
🌐
SAPIEN Technologies
sapien.com › home › windows powershell › powershell functions: return vs write
PowerShell Functions: Return vs Write - SAPIEN Blog
June 2, 2009 - I was a fan of return, but I’m ... as to the ambiguity of the return statement though.. it returns to the value to the place where the function was called from....
🌐
TechTarget
techtarget.com › searchwindowsserver › tutorial › Cut-coding-corners-with-return-values-in-PowerShell-functions
Cut coding corners with return values in PowerShell functions | TechTarget
March 29, 2021 - Because we can return values from a PowerShell function, the value of the return keyword might not immediately be evident. The difference between returning values with Write-Output and the return keyword is using the return keyword exits the current scope.
Find elsewhere
🌐
SS64
ss64.com › ps › return.html
Return statement - PowerShell
In PowerShell, the result of each statement is returned as output, even without an explicit Return keyword. So $price return has exactly the same effect as: return $price ... function demoadd { param ($value) "Adding five" $value += 5 return $value } PS C:\> $result = demoadd 2 PS C:\> PS C:\> ...
🌐
PowerShell Forums
forums.powershell.org › powershell help
Explaining Rationale for Function Output Behavior - PowerShell Help - PowerShell Forums
October 3, 2016 - Ok, so I discovered (the hard way) how functions sort of queue up any output from within the function and then return all of it as part of the return object. function foo () { echo "SettingVar" $var = "varValue" echo "VarSet" return $var } > foo SettingVar varValue VarSet I initially found this to be idiotic.
🌐
PowerShell Forums
forums.powershell.org › powershell help
newbie question on function return values - PowerShell Help - PowerShell Forums
January 24, 2018 - All, trying to develop a simple function that does an evaluation and returns $true or $false, but the result always returns $false. What’s up with that? Am I doing something stupid here? The code works outside of the function. $var = 'VDI' function is_billable([String]$cb) { $list = [String]"'VDI','MOD','MDI'" if($list -match $cb) { $result =$true } else { $result = $false } return $result } $test = is_billable($var) always comes back false
🌐
Davemason
davemason.me › 2021 › 11 › 29 › powershell-functions-and-return-types
PowerShell Functions and Return Types - It's All Just Electrons
This is definitely top 3 of the most idiotic things the Powershell devs did. c# doesn't try and override your return values, whoever designed this should be off of the Powershell project. Brad · Here is a work around stackoverflow.com/.../function-return-value-in-powershell& Get-RandomDate()
{ [OutputType([System.DateTime])] Param ( [parameter(Mandatory=$true)] [System.Int32] $DaysAgo ) { [System.DateTime]$ret = [System.DateTime]::Today $randomDays = Get-Random -Minimum 0 -Maximum $DaysAgo $ret = [System.DateTime]::Today.AddDays($randomDays * -1) [System.Text.StringBuilder] $sb = New-Object System.Text.Stringbuilder $sb.Append("Hello ") $sb.Append("world!") } | Out-Null; return $ret } Brad
🌐
Collecting Wisdom
collectingwisdom.com › home › powershell: how to return multiple values from function
PowerShell: How to Return Multiple Values from Function - Collecting Wisdom
February 27, 2024 - This tutorial explains how to return multiple values from a function in PowerShell, including an example.
🌐
SharePoint Diary
sharepointdiary.com › sharepoint diary › powershell › how to return value from a function in powershell?
How to Return Value from a Function in PowerShell? - SharePoint Diary
March 26, 2026 - For example: function Get-Sum { param($a, $b) return $a + $b } Get-Sum -a 5 -b 10 # Output: 15 PowerShell automatically returns the last expression. ... PowerShell handles function output differently compared to traditional programming languages. Any value that’s sent to the pipeline inside a function becomes part of the function’s output.
🌐
Microsoft Learn
learn.microsoft.com › en-us › powershell › module › microsoft.powershell.core › about › about_execution_policies
about_Execution_Policies - PowerShell | Microsoft Learn
To set the execution policy for a new session, start PowerShell at the command line, such as cmd.exe or from PowerShell, and then use the ExecutionPolicy parameter of pwsh.exe to set the execution policy. ... The execution policy that you set isn't stored in the configuration file. Instead, it's stored in the $Env:PSExecutionPolicyPreference environment variable. The variable is deleted when you close the session in which the policy is set. You cannot change the policy by editing the variable value.
🌐
Roblox Developer Forum
devforum.roblox.com › resources › community resources
[V1.2] Blueprint Roblox Editor : Visual programming tools for Luau - Community Resources - Developer Forum | Roblox
November 9, 2025 - BlueprintRobloxEditor BRE (Blueprint Roblox Editor) is a blueprint editor for creating Roblox games using a plugin within Roblox Studio. The project uses Rojo, a VS Code extension for managing Roblox projects. D…
🌐
Powershellstation
powershellstation.com › 2011 › 08 › 26 › powershell’s-problem-with-return
PowerShell’s Problem with Return | PowerShell Station
August 27, 2011 - In the absence of any statements writing to the output stream (with write-output) or “dropping” their values, “return 1″ will cause the caller to receive the value “1″. Using write-output is pretty obvious, and I’d recommend using it explicitly if you intend to add objects to the output stream (thereby including them in the eventual function value).
🌐
Shibata
blog.shibata.tech › entry › 2015 › 07 › 05 › 114903
PowerShellにおける"戻り値"と"Return"について - しばたテックブログ
July 5, 2015 - # 戻り値を返したくない場合は[void]でキャストする PS C:\> [void]$Value · 補足として、PowerShellの言語仕様書の7章(Expressions)に記載されている例をすこしだけ紹介します。 · # 代入なので値は返されない $a = 1234 * 3.5 # ()でくくると$aが評価されるので 4319 が返される ($a = 1234 * 3.5) # インクリメントは代入扱い ++$a # ()でくくると値が返される (++$a()) # 値は返されない $($i = 10) # 10が返される $(($i = 10)) return文はあくまでも制御を呼び出し元に戻すだけの構文となります。 about_Returnにも書かれていますが、
🌐
Day3bits
day3bits.com › 2023-12-08-return-multiple-objects-from-a-powershell-function
Return Multiple Objects from a PowerShell Function | Day 3 Bits
December 8, 2023 - This function doesn't do anything other than return three arrays, but you get the idea. You can return any kind of object, or a mix of different object types. Cool! ... At this point, it's helpful to remember that everything in PowerShell is an object. (Yes, even strings are objects!)
🌐
Expo Documentation
docs.expo.dev › expo tutorial › create your first app
Create your first app - Expo Documentation
A macOS, Linux, or Windows (PowerShell and WSL2) with a terminal window open.
Published   October 10, 2024
Top answer
1 of 4
10

Hi ! I have 2 function in my Script powershell. One get the value of the user and the other one use the values. I found a way to return multiple values from a function (Table).It’s working perfectly .But the values are not recognized by the second function ($Return[1] is empty). Do anyone knows the problem of my code ?

Thanks

$Button2.Add_Click({test1})

$BtnConfirm.Add_Click({test2})

Function test1($Folders,$CheckValue, $UserResearch)
{   

    $Folders = $TextBoxLink.Text
    $CheckValue = $True

    if($CheckBoxYes.Checked -eq $true)
    {
        $CheckValue = $True
    }

    elseif($CheckBoxNo.Checked -eq $true)
    {
        $CheckValue = $False
    }

    $UserResearch = $TextBoxUser.Text
    
    Return $Folders,$CheckValue,$UserResearch

}

$Return = test1

Function test2($Return)
{
   
    ###################################### SI FILTRE ################################
    
    if($Return[1] -eq $True)
    {
        New-Item -Name "superCaMarche.txt" -Path \\srv-files\RNS_Services\Informatique\Test_Depraz -Value $CheckValue
        
        #Récupère le nom de domaine
        $Domain = (Get-ADDomain).NetBIOSName

            #Sotck dans une variable les objects du dossier donné par l'utilisateur 
            $Folders = Get-Item -Path $Path

                #Parcours le dossier ou l'arborescence
                ForEach ($Folder in $Folders)
                {   

                    #Récupère les droits sur un dossier et les stocks
                    $ACLs = Get-Acl $Folder.FullName | ForEach-Object { $_.Access }

                    #Parcours tous les droits sur un dossier
                    ForEach ($ACL in $ACLs)
                    {  
    
                    #Controle si il existe bien des droits  
                    If ($ACL.IdentityReference -match "\\")
                        {   
                        #Controle si le dossier possède des droits lié au domaine
                        If ($ACL.IdentityReference.Value.Split("\")[0].ToUpper() -eq $Domain.ToUpper())
                            { 
                            #Entre dans une variable le nom du groupe AD
                             $Name = $ACL.IdentityReference.Value.Split("\")[1]

                                #Vérifie que l'object récupéré est bien un groupe
                                If ((Get-ADObject -Filter 'SamAccountName -eq $Name').ObjectClass -eq "group")
                                {   

                                #Parcours les informations du groupe récupéré 
                                ForEach ($User in (Get-ADGroupMember $Name -Recursive | Select -ExpandProperty Name))
                                    {   $Result = New-Object PSObject -Property  @{
                                            Path = $Folder.Fullname
                                            Group = $Name
                                            User = $User
                                            FileSystemRights = $ACL.FileSystemRights
                                            AccessControlType = $ACL.AccessControlType
                                            Inherited = $ACL.IsInherited
                                        }
                                        $Result | Select group,FileSystemRights,AccessControlType,Inherited, User |Where-Object{$User.Equals($UserResearch)} |export-csv \\srv-files\RNS_Services\Informatique\Test_Depraz\"$UserResearch".csv -Append
                                        #$Result | Select Path,Group,User,FileSystemRights,AccessControlType,Inherited
                                    }
                                }
                            }
                        }
                    }
                }
           }       
2 of 4
1

Either return a string that you then parse out separate values using delimiters, or return a data structure like an array.

Powershell - Pass array from one function to another Programming & Development
All right, so the basics: I have a 1 button, the first button calls a function which returns an array. I have another button that needs to use the array from the first function. I've tried calling the first function from the second function and have a return statement for my array. The code for this is pretty long, but in a general sense it's just how to I return an array from one function and then use it in a second function. I've been Googleing all yesterday and haven't found anything. B…
🌐
Codewrecks
codewrecks.com › post › general › powershell › powershell-return-value
Return value in PowerShell, a typical error • Codewrecks
April 17, 2021 - If I dump the location of nunit executable in my main script, I can see that the value returned is not what I’m expecting. It is obvious that I’m looking at the output of Nuget.exe executables, and that was caused by missing of the nunit and nuget.exe tools in GH Action machine temp folder, so I run nuget install inside the function. The obvious solution is adding a Out-Null to avoid output to be returned · It is of uttermost importance that you pay attention on what goes in the output during a PowerShell function that is supposed to return something, because you can end spending 20 minutes on trivial errors like this ones.