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

martin

Re: Protecting credentials used for automation

I have updated the article for more clarity.

For a more specific example of use of the Read-Host ..., see also the C# section of the article.
BR365

Protecting credentials used for automation

Hello,
I've already read the information about the Protecting of credentials (https://winscp.net/eng/docs/guide_protecting_credentials_for_automation). But I still don't know exactly how to put all this together.

At the moment, I have a batch file and a config file. The Batch is defining some standard path informations and the config file manages the SFTP transfer.

I also understand how to encrypt the password and created an XML file as shown in the example with the encrypted password.

But how can I now use this part:

# Read XML configuration file
[xml]$config = Get-Content ".\config.xml"
 
# Use read credentials
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "example.com"
    UserName = $config.Configuration.UserName
    Password = $config.Configuration.Password
}


and

Read-Host -AsSecureString | ConvertFrom-SecureString


and

$sessionOptions.SecurePassword = ConvertTo-SecureString $config.Configuration.Password


Can someone provide me a complete example, not only these fragments?

Thanks,
Moritz