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
== EDIT 2023 ==
Original is archived, install newer fork with:
Install-Module -Name TUN.CredentialManager
Check out Github repository for more details.