![]() In production, I obviously would not use a temporary location. The setting of the $LocalFilePath is pretty simple. Read-host -AsSecureString | ConvertFrom-SecureString | Out-File $LocalFilePath \ cred_ $env : UserName. ![]() To do this, I will assume that it’s ok to interactively enter the plain text password once. The obvious next step then is to somehow create an encrypted password and to use that. This means anyone with access to that script now has access to the password which is far from ideal. However, as you’re probably worried about, the secure password is now embedded as plaintext in your script. You have a script you can save and run as needed. Normally this cmdlet expects an encrypted string, which is not what you are passing to it, but it can be forced to take a plaintext string and convert it to a secure string. It can also convert plain text to secure strings. As the synopsis states, Converts encrypted standard strings to secure strings. The key here is the second example in the syntax where it shows the parameters of –AsPlainText and –Force. This command will pop up the following window Get-help -ShowWindow ConvertTo-SecureString The easiest way to do this, of course, is via the command To understand what this does, it is worth checking out the help on this cmdlet. This is why you see the cmdlet ConvertTo-SecureString as the second line in the above script. The trick is, PSCredential requires a secure string for the password. Fortunately, the authors of PowerShell had security in mind and essentially force you to be secure. However, if you try passing in a normal string as the password, you’ll get an error. My first inclination was to pass in a normal string to both the username and password, and indeed, a standard string for the username actually works. This credential object then can be used by the New-SFTPSession cmdlet. This cmdlet takes the username and password and creates a credential object. If you run the above script with the provided username, password and SFTP server, you’ll see it automatically creates the session without prompting you for any information. PowerShell and Secure Strings - Simple Talk Skip to content
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |