Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

dkimmo

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...