gpt4 book ai didi

powershell - cmd中相当于 "%*"的powershell是什么?

转载 作者:行者123 更新时间:2023-12-03 16:26:55 24 4
gpt4 key购买 nike

如何在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com