Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Powershell equivalent for bash $*?

Tags:

powershell

In other words how can I get the command line of the script itself?

So, I know about $PSBoundParameters, but it is not the same. I just want to get the string containing the passed in parameters as is.

How do I do it?

like image 757
mark Avatar asked Nov 02 '25 04:11

mark


1 Answers

See get-help about_Automatic_Variables.

$Args
   Contains an array of the undeclared parameters and/or parameter
   values that are passed to a function, script, or script block.
   When you create a function, you can declare the parameters by using the
   param keyword or by adding a comma-separated list of parameters in
   parentheses after the function name.

   In an event action, the $Args variable contains objects that represent
   the event arguments of the event that is being processed. This variable
   is populated only within the Action block of an event registration
   command.  The value of this variable can also be found in the SourceArgs
   property of the PSEventArgs object (System.Management.Automation.PSEventArgs)
   that Get-Event returns.

Example:

test.ps1

param (
)

Write-Output "Args:"
$args

Output:

PS L:\test> .\test.ps1 foo bar, 'this is extra'
Args:
foo
bar
this is extra
like image 180
Kory Gill Avatar answered Nov 03 '25 20:11

Kory Gill