Created
January 17, 2021 18:47
-
-
Save gthieleb/e0109aafab54a91a61a6c395c154759b to your computer and use it in GitHub Desktop.
powershell password file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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