Guest User

Untitled

a guest
Apr 24th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <#
  2. .SYNOPSIS
  3. Securing Reusable Passwords in PowerShell for Automated Scripting
  4.  
  5. .DESCRIPTION
  6. Stores Encrypted Passwords in Files Using Native PS Secure Strings
  7. Written on Request for Information by Alex, 26th September 2017 and Provided as File
  8. Uploaded to GitHub for further Distribution 17th April 2018 on further Request
  9.  
  10. .OUTPUTS
  11. Script Root Output of sString.key
  12.  
  13. .NOTES
  14. Version: 0.1
  15. Author: GrumpyBum
  16. Creation Date: 26th September 2017
  17. Purpose/Change: Example Script
  18.  
  19. .EXAMPLE
  20. PS C:\temp> Get-Content .\sSecure.key
  21. demouser
  22. 01000000d08c9ddf0115d1118c7a00c04fc297eb01000000b143ed7c1654b841aa94e1be533103a90000000002000000000003660000c000000010000000ec52c69a87b2765ac69a4472679357e10000000004800000a000000010
  23. 00000006880d18a735024c9ff9103678742c2f28000000d5f45a3697631c28577cde4da9035da3982eb14b1074dbe04320bf2335eb72c5e6a35bf6a69830f114000000b51dd7f00b4d69145bda09358586aa87226f1a3a
  24. #>
  25.  
  26. #To Write New File Delete or Rename .\sSecure.key
  27. if (!(Get-Item .\sSecure.key -ErrorAction SilentlyContinue)) {
  28. $userDetail = Get-Credential # Collects User Information in Native Secure Method
  29. $userDetail.UserName | Out-File .\sSecure.key
  30. #Encrypt Password then Save to File
  31. $userDetail.Password | ConvertFrom-SecureString | Out-File .\sSecure.key -Append
  32. }
  33.  
  34. #Start a Process to Test Saved Credentials
  35. $userName = (Get-Content .\sSecure.key)[0] #Store Username in PowerShell
  36. $userPass = (Get-Content .\sSecure.key)[1] | ConvertTo-SecureString #Store Password in PowerShell as Secure String
  37.  
  38. #Run a Test of the Stored UserName and Password
  39. $userCred = New-Object System.Management.Automation.PSCredential -ArgumentList $userName, $userPass
  40. Start-Process Notepad.exe -Credential $userCred
Add Comment
Please, Sign In to add comment