<#
.SYNOPSIS
    A short one-line action-based description, e.g. 'Tests if a function is valid'
.DESCRIPTION
    A longer description of the function, its purpose, common use cases, etc.
.NOTES
    Information or caveats about the function e.g. 'This function is not supported in Linux'
.LINK
    Specify a URI to a help page, this will show when Get-Help -Online is used.
.EXAMPLE
    Test-MyTestFunction -Verbose
    Explanation of the function or its result. You can include multiple examples with additional .EXAMPLE lines
#>

function Get-ITDPasswordList {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true)]
        [string]
        $PasswordList,
        
        [PSCredential]
        $Credential
    )
    
    begin {

    }
    
    process {
        $Uri = "https://itdpv.nd.gov/winapi/searchpasswordlists/?"

        If ($PasswordList) { $Uri += "PasswordList=$PasswordList" }
        $Uri = $Uri.TrimEnd('&')
        
        $InvokeRestMethodParams = @{
            Method = 'Get';
            Uri = $Uri;
        }
        If ($PSBoundParameters.ContainsKey('Credential')){
            $InvokeRestMethodParams += @{Credential = $Credential}
        } Else {
            $InvokeRestMethodParams += @{UseDefaultCredentials = $true}
        }

        $reply = Invoke-RestMethod -Method Get -Uri $Uri -Credential $Credential
        If ($PasswordList) {
            $result = $reply | Where-Object PasswordList -EQ $PasswordList
        }
        Else {
            $result = $reply
        }
    }
    
    end {
        Write-Output $result
    }
}