0

I expected this code to run Foo():

function Foo {
    [Console]::WriteLine("Foo")
}
$Bar = [Console]::ReadLine()
# If $Bar is Foo then it should do the function "Foo", right?

$Bar()
0

1 Answer 1

0

Functions in powershell follow a verb-noun pattern and most .NET methods have a powershell equivalent known ascmdlet so your function can be :

function Get-Foo {
    #[Console]::WriteLine('Foo')
    Write-Host 'This is foo'
}

Get-Foo

or

$Bar = Get-Foo

$Bar

Get-Command and Get-Help are your friends, try them out.

Sign up to request clarification or add additional context in comments.

2 Comments

Doesn't exactly do what I want it to, I think that's my fault for making it too broad, I fixed it to be what I actually want to do.
you feed $bar with user input from [console]::readline() which will always be a string.... foo function` and foo string are not the same thing

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.