Get-credentials

You can use the code below to save your password in an encrypted text file. This text file can be called to authenticate you in other sessions. It negates the need for you to manually authenticate or store your password in clear text.

$Username = $env:username
$Folder = "\\server\folder"
$CredsFile = "$Folder\$Username-PowershellCreds.txt"
Write-Host 'Credential file not found. Please enter your password:' -ForegroundColor Red
Read-Host -AsSecureString | ConvertFrom-SecureString | Out-File $CredsFile
$Password = Get-Content $CredsFile | ConvertTo-SecureString
Posted in Guides Tagged with:

Leave a Reply

Your email address will not be published. Required fields are marked *

*