document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. $StoredCredentials = "$Home\\Documents\\WindowsPowerShell\\Credentials"
  2. if(-not (Test-Path -Path $StoredCredentials)) {
  3.     New-Item -Path $StoredCredentials -ItemType Directory -Force | Out-Null
  4. }
  5.  
  6. if(-not (Test-Path -Path \'AuthStore:\')) {
  7.     New-PSDrive -Name \'AuthStore\' -PSProvider FileSystem -Root $StoredCredentials -Scope global | Out-Null
  8. }
  9.  
  10. function Export-Credential {
  11.     Param (
  12.     [Parameter(Mandatory)]
  13.     [System.Management.Automation.PSCredential]
  14.     $Credential,
  15.     [Parameter(Mandatory)]
  16.     [System.String]
  17.     $LookupKey
  18.     )
  19.     $FullName = $( \'AuthStore:\\{0}\' -f $LookupKey )
  20.     if(Test-Path -Path $FullName) { Write-Warning -Message "Updateing Credential Associated with Key $LookupKey" }
  21.     $CredentialCopy = $Credential | Select-Object *
  22.     $CredentialCopy.Password = $CredentialCopy.Password | ConvertFrom-SecureString
  23.     $CredentialCopy | ConvertTo-Json | Set-Content -Path $FullName -Force
  24. }
  25.  
  26.  
  27. function Import-Credential {
  28.     param (
  29.     [Parameter(Mandatory=$true)]
  30.     [System.String]
  31.     $LookupKey
  32.     )
  33.     $FullName = $( \'AuthStore:\\{0}\' -f $LookupKey )
  34.     if(-not (Test-Path -Path $FullName)) {
  35.         Write-Error -Message \'No Credential Found\'
  36.         return
  37.     }
  38.     $CredentialCopy = Get-Content -Path $FullName -Raw | ConvertFrom-Json
  39.     $CredentialCopy.password = $CredentialCopy.Password | ConvertTo-SecureString
  40.     New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $CredentialCopy.username, $CredentialCopy.password
  41. }
');