Public/Save-VsoToken.ps1

<############################################
    Module : VsoReleaseManagerClient
    Company : ItsZap Inc.
    Author : Riwut Libinuko
    Blog : http://blog.libinuko.com
    Licence : GNU GENERAL PUBLIC LICENSE
    Copyright © 2016, ItsZap Inc, Riwut Libinuko (cakriwut@gmail.com). All Rights Reserved
#############################################>


function Save-VsoToken{

param(
  [Parameter(Mandatory=$true)] 
  [String]$vstsAccount,
  [Parameter(Mandatory=$true)]
  [String]$token)
    $credPath = [Environment]::GetFolderPath("MyDocuments") + "\" + $vstsAccount + ".credential"
    $PWord = Encode-SecureString -String $token 
    $Credential = New-Object System.Management.Automation.PSCredential($vstsAccount, $PWord)
    $Credential | Export-CliXml $credPath -Encoding UTF8 

}

function Encode-SecureString {
   #.Synopsis
   # Encodes a string as a SecureString (for this computer/user)
   [CmdletBinding()]
   [OutputType("System.Security.SecureString")]
   param(
      # The string to encode into a secure string
      [Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
      [String]$String
   )
   end {
      [char[]]$Chars = $String.ToString().ToCharArray()
      $SecureString = New-Object System.Security.SecureString
      foreach($c in $chars) { $SecureString.AppendChar($c) }
      $SecureString.MakeReadOnly();
      Write-Output $SecureString
   }
}