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

标签 powershell batch-file cmd scripting

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

相关文章:

loops - Powershell遍历文件夹,在每个文件夹中创建文件

powershell - 使用 DACFx 3.0 API 升级 DACPAC - 如何检查现有数据库的当前 DAC 版本?

windows - 在批处理文件的参数中转义“、<、>、>> 或 | 等字符

Python 在退出时关闭自己的 CMD shell 窗口

cmd - 如何在 Windows CMD 中的单行命令之间插入注释?

c# - 通过C#执行PowerShell函数脚本

powershell - 无法使用Powershell从商店中删除证书

python - 如何使用文件名创建文件夹,然后将文件移动到文件夹中?

linux - 使用 Plink 将批处理文件中的多个参数传递给远程 shell 脚本时出现问题

date - 在 Windows 7 批处理作业中格式化日期