Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .SYNOPSIS
- Securing Reusable Passwords in PowerShell for Automated Scripting
- .DESCRIPTION
- Stores Encrypted Passwords in Files Using Native PS Secure Strings
- Written on Request for Information by Alex, 26th September 2017 and Provided as File
- Uploaded to GitHub for further Distribution 17th April 2018 on further Request
- .OUTPUTS
- Script Root Output of sString.key
- .NOTES
- Version: 0.1
- Author: GrumpyBum
- Creation Date: 26th September 2017
- Purpose/Change: Example Script
- .EXAMPLE
- PS C:\temp> Get-Content .\sSecure.key
- demouser
- 01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b143ed7c1654b841aa94e1be533103a90000000002000000000003660000c000000010000000ec52c69a87b2765ac69a4472679357e10000000004800000a000000010
- 00000006880d18a735024c9ff9103678742c2f28000000d5f45a3697631c28577cde4da9035da3982eb14b1074dbe04320bf2335eb72c5e6a35bf6a69830f114000000b51dd7f00b4d69145bda09358586aa87226f1a3a
- #>
- #To Write New File Delete or Rename .\sSecure.key
- if (!(Get-Item .\sSecure.key -ErrorAction SilentlyContinue)) {
- $userDetail = Get-Credential # Collects User Information in Native Secure Method
- $userDetail.UserName | Out-File .\sSecure.key
- #Encrypt Password then Save to File
- $userDetail.Password | ConvertFrom-SecureString | Out-File .\sSecure.key -Append
- }
- #Start a Process to Test Saved Credentials
- $userName = (Get-Content .\sSecure.key)[0] #Store Username in PowerShell
- $userPass = (Get-Content .\sSecure.key)[1] | ConvertTo-SecureString #Store Password in PowerShell as Secure String
- #Run a Test of the Stored UserName and Password
- $userCred = New-Object System.Management.Automation.PSCredential -ArgumentList $userName, $userPass
- Start-Process Notepad.exe -Credential $userCred
Add Comment
Please, Sign In to add comment