<#
.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 Export-ITDPasswordList {
    [CmdletBinding()]
    param (
        [string]
        $PasswordList,

        [string]
        $Destination,
        
        [PSCredential]
        $Credential
    )
    
    begin {
        $PasswordListSearch = Get-ITDPasswordList -PasswordList $PasswordList -Credential $Credential
        switch (@($PasswordListSearch).count) {
            { $_ -gt 1 } {
                Write-Error -Message "More than one password list found, adjust search" -ErrorAction Stop
            }
            { $_ -le 0} {
                Write-Error -Message "Zero password lists found, adjust search" -ErrorAction Stop
            }
            { 1 }{
                $PasswordListId = $PasswordListSearch.PasswordListId
            }
        }
    }
    
    process {
        $PasswordstateUrl = ("https://itdpv.nd.gov/winapi/passwords/" + $PasswordListId + "?QueryAll&PreventAuditing=true")
        $Passwords = Invoke-RestMethod -Method GET -Uri $PasswordstateUrl -Credential $Credential
        $Passwords | Export-Csv -Path $Destination
    }
    
    end {
        
    }
}