How does one securely handle passwords in a custom written PowerShell cmdlet?

后端 未结 5 701
没有蜡笔的小新
没有蜡笔的小新 2021-01-22 16:43

Assume I have a custom PowerShell Cmdlet that exports data and encrypts it using a password.

[Cmdlet(VerbsData.Export, \"SampleData\")]
public class ExportSample         


        
5条回答
  •  醉梦人生
    2021-01-22 17:24

    You can find in this answer a way to crypt with the computer password (works on safe machines).

    Using @Christian response you can put the password to the disk like this :

    PS > $cred.Password | ConvertFrom-SecureString | Set-Content c:\temp\password.txt
    

    And retreive it with :

    $password = Get-Content c:\temp\password.txt | ConvertTo-SecureString
    $cred = New-Object System.Management.Automation.PsCredential "UserName",$password
    

提交回复
热议问题