Skip to content

Instantly share code, notes, and snippets.

@RobsonAutomator
Last active June 6, 2017 21:56
Show Gist options
  • Save RobsonAutomator/7c909cf9f8ec6193c92642b718837abb to your computer and use it in GitHub Desktop.
Save RobsonAutomator/7c909cf9f8ec6193c92642b718837abb to your computer and use it in GitHub Desktop.
A simple Powershell credentials store
# See also: http://lets-share.senktas.net/2017/06/powershell-simple-credentials-store.html
# See also: https://www.powershellgallery.com/packages/sitecore-automation/1.3.0.0
# Uncomment two below lines for a first use
#Install-Module Sitecore-Automation -Force -Verbose
#Import-Module Sitecore-Automation -Force -Verbose
# Create a new credentials
New-StoredCredential -Key "SMTP-Server" -Username "SMTP-User" -Password ( "password" | ConvertTo-SecureString -AsPlainText -Force)
New-StoredCredential -Key "SQL-Server" -Username "SQL-User" -Password ( "password" | ConvertTo-SecureString -AsPlainText -Force)
$file = Join-Path "C:\Temp" -ChildPath 'credentials.csv'
#Export credentials to the CSV file
Export-CredentialStore -Path $file
# reset credential store
$script:credentialsStore = @()
# Read credentials from a CSV file
Import-CredentialStore -Path $file
$item1 = Get-StoredCredential -Key "SMTP-Server"
$item2 = Get-StoredCredential -Key "SQL-Server"
# Decrypt data
ConvertTo-PlainText -Secret $item1.Username | Write-Output
ConvertTo-PlainText -Secret $item1.Password | Write-Output
ConvertTo-PlainText -Secret $item2.Username | Write-Output
ConvertTo-PlainText -Secret $item2.Password | Write-Output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment