如何在 powershell 函数中编写以下 cmd 脚本:
@echo off
C:\bin\command.exe %*
Powershell 脚本:
function f{
[CmdletBinding()] Param()
# .. Code? ...
}
最佳答案
如果你想定义一个 param
block 并仍然捕获所有参数,你可以定义一个参数,该参数使用 Parameter
上的 ValueFromRemainingArguments
参数属性。
function Test-Function {
[CmdletBinding()]
param(
[string] $FirstParameter,
[Parameter(ValueFromRemainingArguments=$true)]
[object[]] $RemainingArguments
)
end {
$PSBoundParameters
}
}
Test-Function first and then the rest go to remaining
# Key Value
# --- -----
# FirstParameter first
# RemainingArguments {and, then, the, rest...}
关于powershell - cmd中相当于 "%*"的powershell是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47802500/