Skip to content

Instantly share code, notes, and snippets.

@gthieleb
Created January 17, 2021 18:47
Show Gist options
  • Save gthieleb/e0109aafab54a91a61a6c395c154759b to your computer and use it in GitHub Desktop.
Save gthieleb/e0109aafab54a91a61a6c395c154759b to your computer and use it in GitHub Desktop.
powershell password file
## 1. If file does not exist create file and encrypt password.
## 2. Else Read decrypted password and print on screen.
## 3. Additionally set password to clipboard.
$PASSFILE = "$HOME\pass.txt"
If (!(Test-Path $PASSFILE)) {
$sstring = Read-Host "Enter a password for user account: " -AsSecureString
$secure = $sstring | ConvertFrom-SecureString
$secure | Out-File $PASSFILE
} Else {
$plain = Get-Content $PASSFILE | ConvertTo-SecureString
$cred = new-object -typename System.Management.Automation.PSCredential -argumentlist "Username",$plain
$password = $cred.GetNetworkCredential().password
Write-Host "Entered password: $password (Password was copied to clipboard)"
Set-Clipboard "$password"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment