PowerShell小僧:スクリプトフォルダーの取得 [コンピューター]
最新版のPowerShell(7.2)をインストールしたら、エラーとなるスクリプトが出てきた。
https://docs.microsoft.com/ja-jp/powershell/scripting/whats-new/what-s-new-in-powershell-72?view=powershell-7.2
調べると、以下の記述のところらしい。
$ScriptPath1 = Split-Path $MyInvocation.MyCommand.Path -Parent
スクリプトフォルダーの取得方法には、もう1つ方法あって、$PSScriptRootでもいいらしい。そこでエラーとなる記述を次の様に変更した。
if($PSVersionTable.PSVersion.Major -ge 3){
$ScriptPath1 = $PSScriptRoot
}else{
$ScriptPath1 = Split-Path $MyInvocation.MyCommand.Path -Parent
}
【参考】
https://www.vwnet.jp/Windows/PowerShell/pwd.htm
とりあえず、この変更でエラーは回避できた。
https://docs.microsoft.com/ja-jp/powershell/scripting/whats-new/what-s-new-in-powershell-72?view=powershell-7.2
調べると、以下の記述のところらしい。
$ScriptPath1 = Split-Path $MyInvocation.MyCommand.Path -Parent
スクリプトフォルダーの取得方法には、もう1つ方法あって、$PSScriptRootでもいいらしい。そこでエラーとなる記述を次の様に変更した。
if($PSVersionTable.PSVersion.Major -ge 3){
$ScriptPath1 = $PSScriptRoot
}else{
$ScriptPath1 = Split-Path $MyInvocation.MyCommand.Path -Parent
}
【参考】
https://www.vwnet.jp/Windows/PowerShell/pwd.htm
とりあえず、この変更でエラーは回避できた。
ヤバイぜ! ありがとうございます(^_0)ノ
by cheese999 (2021-11-15 12:42)