プロジェクト

全般

プロフィール

PowerShell関係のメモ

概要

色々メモしておく。大きなったなったら独立する。

メモ

PSスクリプト中でスクリプトのパスを取得

自分の位置を知りたくなったときなどに使う

$MyInvocation.MyCommand.Source

各変数の型も調べておこう。

Write-Output $MyInvocation.GetType()
Write-Output $MyInvocation.MyCommand.GetType()
Write-Output $MyInvocation.MyCommand.Source.GetType()

実行結果:

IsPublic IsSerial Name                                     BaseType
-------- -------- ----                                     --------
True     False    InvocationInfo                           System.Object
True     False    ExternalScriptInfo                       System.Management.Automation.CommandInfo
True     True     String                                   System.Object

$MyInvocation.MyCommand.SourceはString型らしい