Powershell example in Protecting credentials used for automation doesn't work
After reading through the Protecting credentials used for automation section in the docs, I copied the Powershell code and created a script to test it:
Do I have a syntax error? Why isn't WinSCP substituting $config.Configuration.Password correctly for the actual password?
# Read XML configuration file [xml]$config = Get-Content "D:\test\configs\mediaserver.xml" Write-Host $config.Configuration.Password # This writes the correct password to the screen # The session won't open with this code: # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "usefulmedia.com" UserName = "gplimpton" Password = $config.Configuration.Password PortNumber = "2222" } # The session opens correctly with this code: # Set up session options $sessionOptions = New-Object WinSCP.SessionOptions -Property @{ Protocol = [WinSCP.Protocol]::Sftp HostName = "usefulmedia.com" UserName = "gplimpton" Password = "actualpasswordstring" PortNumber = "2222" }
Do I have a syntax error? Why isn't WinSCP substituting $config.Configuration.Password correctly for the actual password?