2016-11-23 1 views
0

つまり、スクリプト自体のコマンドラインを取得するにはどうすればよいですか?

私は$PSBoundParametersについて知っていますが、それは同じではありません。私は、渡されたパラメータをそのまま含む文字列を取得したい。

どうすればよいですか?

+0

"私はただであるようなパラメータに渡された文字列を取得したいです。" - '$ *'はそれをしません。 – user2357112

+0

PowerShellの組み込みパラメータ解析を利用できるときに、なぜそれをやりたいのですか? –

+0

@Bill_Stewart - 私は同じスクリプトで同じコマンドライン引数といくつかの追加のものを使用してpowershell.exeを呼び出す必要があります。 – mark

答えて

2
$MyInvocation.Line 

読むabout_Automatic_Variables

$MyInvocation 
    Contains an information about the current command, such as the name, 
    parameters, parameter values, and information about how the command was 
    started, called, or "invoked," such as the name of the script that called 
    the current command. 

    $MyInvocation is populated only for scripts, function, and script blocks. 
+0

これは素晴らしいです、ありがとう。それについて知らなかった。 – mark

1

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. 

例:

test.ps1

param (
) 

Write-Output "Args:" 
$args 

出力:

PS L:\test> .\test.ps1 foo bar, 'this is extra' 
Args: 
foo 
bar 
this is extra 
+0

私のスクリプトにはかなりの引数がいくつかあります。 – mark

関連する問題