Public/Update-StoredCredential.ps1

<#
    .SYNOPSIS
        This function updates existing credentials in the Windows Credential Manager - or if the credential Target
        doesn't already exist, this function creates a new Windows Credential Manager entry.
 
    .DESCRIPTION
        See .SYNOPSIS
 
    .NOTES
 
    .PARAMETER ServiceName
        This parameter is MANDATORY.
 
        This parameter takes a string that represents the name of the service that you would like to log into via
        Google Chrome (chromedriver.exe). Currently, supported services are:
 
        AmazonMusic, Audible, GooglePlay, InternetArchive, NPR, Pandora, ReelGood, Spotify, Tidal, TuneIn, YouTube,
        and YouTubeMusic
 
    .PARAMETER SiteUrl
        This parameter is OPTIONAL.
 
        This parameter is takes a string that represents the URL of the website where these credentials are used.
 
    .EXAMPLE
        # Open an PowerShell session, import the module, and -
         
        PS C:\Users\zeroadmin> Update-StoredCredential -ServiceName Spotify -SiteUrl "https://open.spotify.com"
#>

function Update-StoredCredential {
    [CmdletBinding()]
    param(
        [parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [ValidateSet("AmazonMusic","Audible","GooglePlay","InternetArchive","NPR","Pandora","ReelGood","Spotify","Tidal","TuneIn","YouTube","YouTubeMusic")]
        [string]$ServiceName,

        [parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]
        [string]$SiteUrl
    )

    $ExistingStoredCreds = Get-StoredCredential -Target $ServiceName -ErrorAction SilentlyContinue
    if ($ExistingStoredCreds) {
        try {
            Remove-StoredCredential -Target $ServiceName -ErrorAction Stop
        } catch {
            Write-Error $_
            return
        }
    }
    
    if ([System.Environment]::OSVersion.Version.Build -lt 10240) {
        try {
            # Have the user provide Credentials
            [pscredential]$PSCreds = GetAnyBoxPSCreds -ServiceName $ServiceName
        } catch {
            Write-Error $_
            return
        }
    } else {
        try {
            if ($SiteUrl) {
                [pscredential]$PSCreds = UWPCredPrompt -ServiceName $ServiceName -SiteUrl $SiteUrl
            } else {
                [pscredential]$PSCreds = UWPCredPrompt -ServiceName $ServiceName
            }
        } catch {
            Write-Error $_
            return
        }
    }

    # Output
    $PSCreds
}