Skip to content

Instantly share code, notes, and snippets.

@RaccoonDev
Created April 21, 2015 20:09
Show Gist options
  • Save RaccoonDev/40d2a6e9d47db5449121 to your computer and use it in GitHub Desktop.
Save RaccoonDev/40d2a6e9d47db5449121 to your computer and use it in GitHub Desktop.
Save Password in Encrypted File
function Save-Password
{
Param
(
[parameter(Mandatory = $true)]
[String]
$FilePath,
[parameter(Mandatory = $true)]
[Switch]
$PassThru
)
$secure = Read-Host -AsSecureString "Enter your Azure organization ID password."
$encrypted = ConvertFrom-SecureString -SecureString $secure
$result = Set-Content -Path $FilePath -Value $encrypted -PassThru
if (!$result)
{
throw "Failed to store encrypted string at $FilePath."
}
if ($PassThru)
{
dir $FilePath
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment