anoopb
anoopb

Reputation: 543

Calling a cmdlet via a value

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!

Upvotes: 0

Views: 54

Answers (1)

fejesjoco
fejesjoco

Reputation: 11903

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

Upvotes: 1

Related Questions