Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is powershell equivalent to "%*" in cmd? [duplicate]

How do I write the following cmd script inside a powershell function:

@echo off
C:\bin\command.exe %*

Powershell Script:

function f{
    [CmdletBinding()] Param()
    # .. Code? ...
}
like image 538
Jeff Hernandez Avatar asked Oct 23 '25 18:10

Jeff Hernandez


1 Answers

If you want to define a param block and still capture all arguments you can define a parameter that uses the ValueFromRemainingArguments argument on the Parameter attribute.

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...}
like image 74
Patrick Meinecke Avatar answered Oct 26 '25 09:10

Patrick Meinecke



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!