Scripts/Get-BPACredentialStoreItem.ps1

function Get-BPACredentialStoreItem {
    <#
        .SYNOPSIS
            Retrieves credentials for the specified BPA server
 
        .DESCRIPTION
            Get-BPACredentialStoreItem stores a server and credential object together in a credential store file.
 
        .PARAMETER BPAServer
            The AutoMate BPA management server.
 
        .PARAMETER FilePath
            The file the server/credential combinations are stored in. It is stored in the user profile by default.
 
        .EXAMPLE
            Get-BPACredentialStoreItem -BPAServer server01
 
        .NOTES
            Author(s): : David Seibel
            Contributor(s) :
            Date Created : 05/04/2017
            Date Modified : 04/27/2018
 
        .LINK
            https://github.com/davidseibel/PoshBPA
    #>

    [CmdletBinding()]
    param(
        [Parameter(Position = 0)]
        [ValidateNotNullOrEmpty()]
        [string]$BPAServer,

        [ValidateScript({
            if (Test-Path -Path $_) {
                $true
            } else {
                throw [System.Management.Automation.PSArgumentException]"FilePath '$_' does not exist!"
            }
        })]
        [string]$FilePath = "$($env:APPDATA)\PoshBPA\credstore.xml"
    )

    $defaultDisplaySet = "BPAServer","UserName"
    $defaultDisplayPropertySet = New-Object System.Management.Automation.PSPropertySet("DefaultDisplayPropertySet",[string[]]$defaultDisplaySet)
    $PSStandardMembers = [System.Management.Automation.PSMemberInfo[]]@($defaultDisplayPropertySet)

    if (Test-Path -Path $FilePath) {
        $Items = Import-Clixml -Path $FilePath 
        if ($BPAServer) {
            $Items[$BPAServer]
        } else {
            foreach ($key in $Items.Keys) {
                [PSCustomObject]@{
                    BPAServer = $key
                    UserName = $Items[$key].UserName
                    Password = $Items[$key].GetNetworkCredential().Password
                    FilePath = $FilePath
                    TypeName = "CredentialStoreItem"
                } | Add-Member MemberSet PSStandardMembers $PSStandardMembers -PassThru
            }
        }
    }
}