0

I have a variable in my psm1 file that's a KVP hash

$subcmdlist = @{
"addhost" = "Add-Host";
"deletehost" = "Remove-Host";
"setparameter" = "Set-Parameter";
}

This psm1 file also has a function called 'newtask' which accepts an argument of $subcommand.

I'm wondering how i can execute the cmdlet Add-Host when

newtask addhost

is issued from the shell.

I tried to just echo it but that didn't do much good at all. Just printed out the value.

Thanks!

1

1 Answer 1

1

Use the & sign (aka the call operator), like this: & "Get-Host". This works at least in Powershell 3.0.

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

1 Comment

I just realized that calling Invoke-Expression may be better suited for this. See here: ss64.com/ps/call.html and here: ss64.com/ps/invoke-expression.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.