つまり、スクリプト自体のコマンドラインを取得するにはどうすればよいですか?
私は$PSBoundParameters
について知っていますが、それは同じではありません。私は、渡されたパラメータをそのまま含む文字列を取得したい。
どうすればよいですか?
つまり、スクリプト自体のコマンドラインを取得するにはどうすればよいですか?
私は$PSBoundParameters
について知っていますが、それは同じではありません。私は、渡されたパラメータをそのまま含む文字列を取得したい。
どうすればよいですか?
$MyInvocation.Line
$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.
これは素晴らしいです、ありがとう。それについて知らなかった。 – mark
は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
私のスクリプトにはかなりの引数がいくつかあります。 – mark
"私はただであるようなパラメータに渡された文字列を取得したいです。" - '$ *'はそれをしません。 – user2357112
PowerShellの組み込みパラメータ解析を利用できるときに、なぜそれをやりたいのですか? –
@Bill_Stewart - 私は同じスクリプトで同じコマンドライン引数といくつかの追加のものを使用してpowershell.exeを呼び出す必要があります。 – mark