Post a reply

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)


Topic review


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.

Protecting credentials used for automation

I've already read the information about the Protecting of credentials ( 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 = ""
    UserName = $config.Configuration.UserName
    Password = $config.Configuration.Password


Read-Host -AsSecureString | ConvertFrom-SecureString


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

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