PowerShell to use WinSCP .NET assembly with secure credentials -
i'm trying utilize winscp .net assembly secure credential, when password secured in external file.
class="lang-powershell prettyprint-override"># load winscp .net assembly add-type -path "d:\winscpnet.dll" # setup session options $sessionoptions = new-object winscp.sessionoptions $sessionoptions.protocol = [winscp.protocol]::sftp # env $sessionoptions.hostname = "blabla.com" $sessionoptions.username = "uuuu" #$sessionoptions.password = "pppp" $sessionoptions.sshhostkeyfingerprint = "xxxxxxxxx" $remotepath = "/home/uuuu/"
with hard coded password working. if utilize securestring password, how should that?
i tried:
class="lang-powershell prettyprint-override">read-host -assecurestring | convertfrom-securestring | out-file d:\securestring.txt
to maintain secure password in file. then, in script, back:
class="lang-powershell prettyprint-override">$sessionoptions.password = get-content d:\securestring.txt | convertto-securestring $cred = new-object -typename system.management.automation.pscredential -argumentlist $sessionoptions.username, $sessionoptions.password}
but it's not working...
since winscp 5.7, assembly accepts securestring
using sessionoptions.securepassword
.
see http://winscp.net/eng/docs/library_sessionoptions
thanks inspiring this improvement.
while assembly keeps password encrypted in memory, still needs decrypt eventually. improvements limit internal copies of decrypted password pending.
powershell credentials winscp winscp-net
No comments:
Post a Comment