Fix for dnvm update-self on PowerShell 2.0

PSScriptRoot variable is not available in PowerShell 2.0. This change make use of a Get-ScriptRoot function which return current script location using PSScriptRoot (in PS >= 3.0) or MyInvocation.MyCommand.Path (in PS < 3.0)

Fix for:
#391
This commit is contained in:
Hubert Bukowski 2015-09-24 19:03:12 +02:00
Родитель 20e77f977d
Коммит bfe17d485a
1 изменённых файлов: 13 добавлений и 4 удалений

Просмотреть файл

@ -846,6 +846,14 @@ function Is-Elevated() {
return $user.IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
}
function Get-ScriptRoot() {
if (!$PSVersionTable.PSVersion.Major -ge 3) {
return $PSScriptRoot
}
return Split-Path $script:MyInvocation.MyCommand.Path -Parent
}
### Commands
<#
@ -863,9 +871,10 @@ function dnvm-update-self {
$wc = New-Object System.Net.WebClient
Apply-Proxy $wc -Proxy:$Proxy
$dnvmFile = Join-Path $PSScriptRoot "dnvm.ps1"
$tempDnvmFile = Join-Path $PSScriptRoot "temp"
$backupFilePath = Join-Path $PSSCriptRoot "dnvm.ps1.bak"
$CurrentScriptRoot = Get-ScriptRoot
$dnvmFile = Join-Path $CurrentScriptRoot "dnvm.ps1"
$tempDnvmFile = Join-Path $CurrentScriptRoot "temp"
$backupFilePath = Join-Path $CurrentScriptRoot "dnvm.ps1.bak"
$wc.DownloadFile($DNVMUpgradeUrl, $tempDnvmFile)