Public/New-WebLogin.ps1

<#
    .SYNOPSIS
        This function uses chromedriver.exe via Selenium to log you into web service specified by the -ServiceName parameter.
 
    .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 ChromeProfileNumber
        This parameter is OPTIONAL.
 
        This parameter is takes an int that represents the Chrome Profile that you would like to use when
        launching Google Chrome via chromedriver.exe. Use the following PowerShell one-liner to list all available
        Chrome Profiles under the current Windows user:
         
        (Get-ChildItem -Path "$HOME\AppData\Local\Google\Chrome\User Data" -Directory -Filter "Profile *").Name
 
    .EXAMPLE
        # Open an PowerShell session, import the module, and -
         
        PS C:\Users\zeroadmin> New-WebLogin -ServiceName AmazonMusic -ChromeProfileNumber 1
#>

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

        [parameter(Mandatory=$false)]
        [ValidatePattern('[0-9]')]
        [int]$ChromeProfileNumber = '0'

        #[parameter(Mandatory=$true)]
        #[ValidateSet("UserNamePwd","Google","Amazon","Apple","Facebook","Twitter")]
        #[string]$LoginType
    )
    DynamicParam {
        # Need dynamic parameters for LoginType
        # Set the dynamic parameters' name
        $paramLoginType = 'LoginType'
        # Create the collection of attributes
        $AttributeCollection = New-Object System.Collections.ObjectModel.Collection[System.Attribute]
        # Create and set the parameters' attributes
        $ParameterAttribute = New-Object System.Management.Automation.ParameterAttribute
        $ParameterAttribute.Mandatory = $true
        #$ParameterAttribute.Position = 1
        # Add the attributes to the attributes collection
        $AttributeCollection.Add($ParameterAttribute)
        # Create the dictionary
        $RuntimeParameterDictionary = New-Object System.Management.Automation.RuntimeDefinedParameterDictionary
        # Generate and set the ValidateSet
        $ParameterValidateSet = switch ($ServiceName) {
            'AmazonMusic'       {@("Amazon")}
            'Audible'           {@("Amazon")}
            'GooglePlay'        {@("Google")}
            'InternetArchive'   {@("UserNamePwd")}
            'NPR'               {@("UserNamePwd","Google","Facebook","Apple")}
            'Pandora'           {@("UserNamePwd")}
            'ReelGood'          {@("UserNamePwd","Google","Facebook")}
            'Spotify'           {@("UserNamePwd","Apple","Facebook")}
            'Tidal'             {@("UserNamePwd","Apple","Facebook","Twitter")}
            'TuneIn'            {@("UserNamePwd","Apple","Facebook","Google")}
            'YouTube'           {@("Google")}
            'YouTubeMusic'      {@("Google")}
        }
        $ValidateSetAttribute = New-Object System.Management.Automation.ValidateSetAttribute($ParameterValidateSet)
        # Add the ValidateSet to the attributes collection
        $AttributeCollection.Add($ValidateSetAttribute) 
        # Create and return the dynamic parameter
        $RuntimeParameter = New-Object System.Management.Automation.RuntimeDefinedParameter($paramLoginType, [string], $AttributeCollection)
        $RuntimeParameterDictionary.Add($paramLoginType, $RuntimeParameter) 
    
        return $RuntimeParameterDictionary
    }

    Begin {
        $LoginType = $PSBoundParameters[$paramLoginType]

        $PSCmdString = $ServiceName + 'SeleniumLoginCheck'
        
        if ($ChromeProfileNumber) {
            $PSCmdString = $PSCmdString + ' ' + '-ChromeProfileNumber' + ' ' + $ChromeProfileNumber
        }

        if ($LoginType) {
            $PSCmdString = $PSCmdString + ' ' + '-LoginType' + ' ' + $LoginType
        }
    }

    Process {
        $global:SuccessfulLogin = $False
        
        try {
            Invoke-Expression -Command $PSCmdString -ErrorAction Stop
        } catch {
            $Msg = "Problem with private function" + $($ServiceName + 'SeleniumLoginCheck') + ': ' + $_.Exception.Message
            Write-Error $Msg
            return
        }
    }
}