The value supplied is not valid, or the property is read-only. Change the value, and then try again

Advertisement

dkimmo
Joined:
Posts:
2
Location:
Australia

The value supplied is not valid, or the property is read-only. Change the value, and then try again

Hi, I'm getting the error mentioned above in a script I'm trying to set up for automated-deployment to a web server. I'm new to both PowerShell scripting and WinSCP so forgive me if this is a common problem, but I did try searching the forum first for similar topics.

Here's the current script I'm trying:
param(
[string]$environment
)
$confirmed = Read-host "Put the site into maintenance mode? (y/n)"
 
if ($confirmed -eq "y") {
    try {
 
    # Load WinSCP .NET assembly
    Add-Type -Path "WinSCPnet.dll"
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::Sftp
        HostName = [System.Net.Dns]::GetHostName()
        UserName = "root"
        Password = "password"
        PortNumber = 2222
        SshHostKeyFingerprint = "ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBPTEv+TGGfNqJeP0uV5E/cYHy3TEtNAT7DJpJcLj7WbHCBtCWAIvtQ2dO8s+vQrNcK5G+W1VrncvitR3RFvB3ag="
    }
 
    $session = New-Object WinSCP.Session
 
    try
    {
        # Connect
        $session.Open($sessionOptions)
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}
} elseif ($confirmed -eq "n") {
    return
}
else {
    Write-Host("Invalid input. Please enter y/n.")
}
Edit: Also, what editor should I be using for PowerShell scripting? Currently trying to use PowerShell ISE but not sure if there's one that will make it easier...

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,441
Location:
Prague, Czechia

Re: The value supplied is not valid, or the property is read-only. Change the value, and then try again

What you pass to SessionOptions.SshHostKeyFingerprint seems like a full host key. While the property accepts a hostkey fingerprint.
See https://winscp.net/eng/docs/faq_hostkey#automation

For general information also see SSH host key/TLS host certificate fingerprint “…” does not match pattern “…”.

Reply with quote

Advertisement

You can post new topics in this forum