Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
53 lines (49 sloc) 1.93 KB
#requires -Version 3.0
Safely save the encrypted password to a file.
The New-SecureCred.ps1 script safely saves the encrypted text (probably password) to a file.
To decrypt that text you MUST meet three conditions:
[1] You are logged on with the same user account used to encrypt the text.
[2] You are logged on to the same computer used to encrypt the data.
[3] You has not changed your password since you have created the encrypted file.
String to encrypt.
Save encrypted password here.
.PARAMETER ShowSecureFile
Open the SecureFile by any text editor.
PS C:\scripts> .\New-SecureCred.ps1 'YourPassword'
Save encrypted password in the default path (the script's root directory).
PS C:\scripts> .\New-SecureCred.ps1 -Password 'A123456a' -SecureFilePath "$(Split-Path $PROFILE)\mycred.txt"
Save encrypted password in your PowerShell profile directory.
PS C:\scripts> .\New-SecureCred.ps1 'A123456a' "$($env:USERPROFILE)\Documents\esx.sec" -Show
Save encrypted password in your `My Documents` folder.
Author :: Roman Gelman
Version 1.0 :: 14-Jun-2016 :: [Release]
Version 1.1 :: 21-Dec-2016 :: [Change] Content based help has been added, minor code changes.
Param (
[Parameter(Mandatory,Position=0,HelpMessage="Enter password to encrypt")]
[Parameter(Mandatory=$false,Position=1,HelpMessage="Secure file full path")]
[ValidateScript({Test-Path (Split-Path $_) -PathType 'Container'})]
[string]$SecureFile = "$PSScriptRoot\secure.cred"
$Password |ConvertTo-SecureString -AsPlainText -Force |ConvertFrom-SecureString |Out-File $SecureFile
If ($ShowSecureFile -and (Test-Path $SecureFile -PathType Leaf)) {Invoke-Item $SecureFile}