LoginSignup
3
3

More than 5 years have passed since last update.

PowerShellで実行中のスクリプトファイルのディレクトリを取得(PowerShell ISE対応版)

Posted at
$ScriptDir = $null

If( $host.Name -match "ise" ){

    # On PowerShell-ISE
    $ScriptDir = Split-Path $psISE.CurrentFile.FullPath -Parent
}
Else{

    # Out of PowerShell-ISE
    If($PSVersionTable.PSVersion.Major -ge 3 ){

        # PS Version >= 3
        $ScriptDir = $PSScriptRoot
    }
    Else{

        # PS Version < 3
        $ScriptDir = Split-Path $MyInvocation.MyCommand.Path -Parent
    }
}
3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3