In powershell5 type:
Install-Module CredentialManager -force
Then
New-StoredCredential -Target $url -Username $ENV:Username -Pass ....
and later
Get-StoredCredential -Target ....
Source code for the module is https://github.com/davotronic5000/PowerShell_Credential_Manager