public/account/Set-PSTSAccount.ps1

function Set-PSTSAccount {
   param(
      [Parameter(Mandatory=$true)][string] $account,
      [Parameter(Mandatory=$true)] [string] $endPoint
   )

   begin {
        $credFile = "$([Environment]::GetFolderPath('ApplicationData'))/REST-Devops/$($account)"

        if ((Test-Path -Path $credFile ) -eq $false) {

            throw [exception]::new("Account file not found")
        }
   }

   process {

       $token = [string]::Empty

        $pwd = (get-content $credFile) | ConvertTo-SecureString

        $creds= New-Object System.Management.Automation.PSCredential($account, $pwd)

        $token = $creds.GetNetworkCredential().Password
   }

    end
    {
        [Environment]::SetEnvironmentVariable("ACCOUNT",$account)
        [Environment]::SetEnvironmentVariable("TOKEN",[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(":$token")))
        [Environment]::SetEnvironmentVariable("ENDPOINT",$endPoint)
    }
}