【发布时间】:2019-06-20 21:20:24
【问题描述】:
我怎样才能生成一个看起来像这样的文件
<Configuration>
<UserName>oracle</UserName>
<Password>01000000d08c9ddf...</Password>
<SshFingerPrint>01000000d08c9ddf0115d...</SshFingerPrint>
</Configuration>
我想在我的脚本中使用 XML 文件
[xml]$config = Get-Content "$PSScriptRoot\config.xml"
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
Protocol = [WinSCP.Protocol]::Scp
HostName = "127.0.0.1"
UserName = $config.Configuration.UserName
Password = ConvertTo-SecureString $config.Configuration.Password
SshHostKeyFingerprint = ConvertTo-SecureString $config.Configuration.SshFingerPrint
}
$session = New-Object WinSCP.Session
【问题讨论】:
-
补充 Martin Prikryl 给你的东西。在 PowerShell 脚本中处理安全凭证是一个经常被谈论和充分覆盖/记录的事情。无论是使用 xml、txt、注册表、数据库还是 Windows 凭据管理器。没有什么能阻止您使用它们来创建您所追求的文件。在此处查看示例源列表:--- reddit.com/r/PowerShell/comments/bv7ywa/… --- 因此,有许多用例可供选择。
标签: xml powershell winscp securestring