* スクリプト自身のパスなどの参照 [#l5974abb]
** $PSScriptRoot [#i25a1558]
- $PSScriptRoot を使う。
*** 例 Microsoft.PowerShell_profile.ps1 [#ua4b7506]
$moduleDir = (join-path $PSScriptRoot modules)
$env:PSModulePath = $moduleDir + ";" + $env:PSModulePath
** PowerShell 2以前 [#a9546d75]
- 自動変数$MyInvocationを参照する。
- コマンド名は$MyInvocation.MyCommandで取得できる。
- その他は以下の通り。
PS tmp> C:\tmp\my-test.ps1 -foo 1 bar
MyCommand : my-test.ps1
BoundParameters : {}
UnboundArguments : {-foo, 1, bar}
ScriptLineNumber : 1
OffsetInLine : 1
HistoryId : 325
ScriptName :
Line : C:\tmp\my-test.ps1 -foo 1 bar
PositionMessage : 発生場所 行:1 文字:1
+ C:\tmp\my-test.ps1 -foo 1 bar
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PSScriptRoot :
PSCommandPath :
InvocationName : C:\tmp\my-test.ps1
PipelineLength : 1
PipelinePosition : 1
ExpectingInput : False
CommandOrigin : Runspace
DisplayScriptPosition :
** 参考 [#u2c517b6]
- https://stackoverflow.com/questions/5466329/whats-the-best-way-to-determine-the-location-of-the-current-powershell-script
- https://technet.microsoft.com/ja-jp/library/hh847768.aspx