How to make a circuit for a function in PowerShell by analogy with JavaScript?

Started to learn PowerShell. Trying to return from a block function, which closes on another function like this:

$myFunction = Invoke-Command -ScriptBlock {
 function Bar {
 Write-Host World
}

 function Foo {
 Write-Host Hello
Bar
}

 return ${function:Foo}
}

. $myFunction

To get the answer:
Hello
foreach : The term 'Bar' is not recognized as the name of a cmdlet, function, script file, or operable program.

Want to get:
Hello
World


It does not want to disclose the function Bar in the global scope. How in PowerShell to do this?
September 26th 19 at 11:56
1 answer
September 26th 19 at 11:58
I got this:

$myFunction = Invoke-Command -ScriptBlock {
 function Bar
{
Write-Host("World")
}

 function Foo
{
 Write-Host("Hello"); 
Bar
}

return Foo

}

$myFunction


Console wrote:

PS C:\Users\%username%> C:\Users\%username%\Desktop\Untitled2.ps1
Hello
World
In the line return Foo is a function call, and not return a reference to the function. And the last line nothing happens at all. - kelsie_Goldner72 commented on September 26th 19 at 12:01

Find more questions by tags PowerShell