Fix password prompt conversion errors

This commit is contained in:
2026-02-02 16:56:11 +01:00
parent c1e1689a55
commit eff1df44dc

View File

@@ -47,19 +47,21 @@ function Assert-Tool {
Assert-Tool "dotnet"
Assert-Tool $WinScpPath
function Read-PlainOrPrompt([string]$Value, [string]$Prompt, [switch]$Secure) {
function Read-PlainOrPrompt([string]$Value, [string]$Prompt, [bool]$Secure = $false) {
if ($Value) { return $Value }
if ($Secure) {
$secure = Read-Host -Prompt $Prompt -AsSecureString
return [Runtime.InteropServices.Marshal]::PtrToStringUni(
[Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
)
$ptr = [Runtime.InteropServices.Marshal]::SecureStringToBSTR($secure)
try { return [Runtime.InteropServices.Marshal]::PtrToStringUni($ptr) }
finally {
if ($ptr -ne [IntPtr]::Zero) { [Runtime.InteropServices.Marshal]::ZeroFreeBSTR($ptr) }
}
}
return Read-Host -Prompt $Prompt
}
$FtpPassword = Read-PlainOrPrompt $FtpPassword "FTP password" -Secure
$WinRmCredentialPass = Read-PlainOrPrompt $WinRmCredentialPass "WinRM password" -Secure
$FtpPassword = Read-PlainOrPrompt $FtpPassword "FTP password" $true
$WinRmCredentialPass = Read-PlainOrPrompt $WinRmCredentialPass "WinRM password" $true
Write-Host "1) Publishing..." -ForegroundColor Cyan
New-Item -ItemType Directory -Force -Path $PublishDir | Out-Null