$Title = 'itdwinautot1.nd.gov'
$Username = 'svczmtest005'
$Credential = $Secret:svcitdiaasauto
$FullRecord = $false
ConvertTo-SecureString -String "things" -AsPlainText -Force
$Uri = 'https://itdpv.nd.gov/winapi/searchpasswords/?'

If ($Title) { $Uri += 'title=' + $Title + '&' }
If ($UserName) { $Uri += 'username=' + "$UserName" + '&' }
$Uri = $Uri.TrimEnd('&')

$InvokeResult = Invoke-RestMethod -Method Get -Uri $Uri -Credential $Credential

$OutResult = $InvokeResult | Select-Object PasswordListID, PasswordList, PasswordID, Title, Description, UserName, @{n = 'SecurePassword'; e = { $_.Password | ConvertTo-SecureString -AsPlainText -Force } }, AccountTypeId, AccountType

If (@($OutResult).count -eq 1) {
    If ($PSCmdlet.ParameterSetName -eq "ToClipboard") {
        $InvokeResult.Password | Set-Clipboard
    }
    If ($FullRecord) {
        Write-Output $OutResult
    }
    Else {
        $OutCred = New-Object System.Management.Automation.PSCredential($OutResult.UserName, $OutResult.SecurePassword)
        Write-Output $OutCred
    }
}
Else {
    Write-Output $OutResult
}