$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
}
}
More than 5 years have passed since last update.
PowerShellで実行中のスクリプトファイルのディレクトリを取得(PowerShell ISE対応版)
Posted at
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme