2024-10-01 15:24:16 +02:00
|
|
|
|
<#
|
2024-01-15 09:59:13 +01:00
|
|
|
|
.SYNOPSIS
|
|
|
|
|
Saves credentials encrypted
|
|
|
|
|
.DESCRIPTION
|
2024-10-28 14:07:23 +01:00
|
|
|
|
This PowerShell script asks for credentials and saves them encrypted into a target file.
|
|
|
|
|
.PARAMETER targetFile
|
|
|
|
|
Specifies the target file ("~\my.credentials" by default)
|
2024-01-15 09:59:13 +01:00
|
|
|
|
.EXAMPLE
|
|
|
|
|
PS> ./save-credentials.ps1
|
|
|
|
|
Enter username and password, please.
|
2024-10-28 14:07:23 +01:00
|
|
|
|
✅ Your credentials have been saved to C:\Users\Markus\my.credentials (encrypted).
|
2024-01-15 09:59:13 +01:00
|
|
|
|
.LINK
|
|
|
|
|
https://github.com/fleschutz/PowerShell
|
|
|
|
|
.NOTES
|
|
|
|
|
Author: Markus Fleschutz | License: CC0
|
|
|
|
|
#>
|
|
|
|
|
|
2024-10-28 14:07:23 +01:00
|
|
|
|
param([string]$targetFile = "~\my.credentials")
|
2024-01-15 09:59:13 +01:00
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
Write-Host "Enter username and password, please." -foreground red
|
|
|
|
|
$cred = Get-Credential
|
2024-10-28 14:07:23 +01:00
|
|
|
|
$cred.Password | ConvertFrom-SecureString | Set-Content "$targetFile"
|
|
|
|
|
"✅ Your credentials have been saved to $targetFile (encrypted)."
|
2024-01-15 09:59:13 +01:00
|
|
|
|
exit 0 # success
|
|
|
|
|
} catch {
|
|
|
|
|
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
|
|
|
|
exit 1
|
|
|
|
|
}
|