如何将参数作为单个字符串传递给powershell命令?

如何将参数作为单个字符串传递给powershell命令?,powershell,arguments,Powershell,Arguments,我有以下几点: function Function-Name { Invoke-Expression (no idea what goes here) } 我想能够写作 Function-Name other command text here …并让此函数使用该调用执行另一个命令。我如何才能做到这一点?您可以设置参数,使参数0接受所有剩余参数,如下所示: function Function-Name{ Param([parameter(Position=0,ValueFromRem

我有以下几点:

function Function-Name
{
    Invoke-Expression (no idea what goes here)
}
我想能够写作

Function-Name other command text here

…并让此函数使用该调用执行另一个命令。我如何才能做到这一点?

您可以设置参数,使参数0接受所有剩余参数,如下所示:

function Function-Name{
Param([parameter(Position=0,ValueFromRemainingArguments=$true)][string]$Command)
    Invoke-Command $Command
}

你能不能用引号把它括起来?函数名或此处的其他命令文本,或仅在函数中使用$args