diff --git a/scripts/Register-BakRestTask.ps1 b/scripts/Register-BakRestTask.ps1 index a432c9f..82c846b 100644 --- a/scripts/Register-BakRestTask.ps1 +++ b/scripts/Register-BakRestTask.ps1 @@ -19,6 +19,19 @@ $ErrorActionPreference = "Stop" $repoRoot = Split-Path -Parent $PSScriptRoot $pythonExe = (& python -c "import sys; print(sys.executable)").Trim() +function Resolve-TaskUserName { + param( + [Parameter(Mandatory = $true)] + [string]$Name + ) + + if ($Name.StartsWith(".\")) { + return "$env:COMPUTERNAME\$($Name.Substring(2))" + } + + return $Name +} + if (-not $pythonExe -or -not (Test-Path -LiteralPath $pythonExe)) { $pythonCommand = Get-Command python -ErrorAction Stop $pythonExe = $pythonCommand.Source @@ -79,6 +92,7 @@ if ($RunAsStoredCredentials) { if (-not $UserName) { $UserName = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name } + $UserName = Resolve-TaskUserName -Name $UserName $securePassword = Read-Host -Prompt "Password for $UserName" -AsSecureString $passwordPtr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($securePassword)