Public/Get-PASAccountList.ps1

Function Get-PASAccountList {
    <#
.SYNOPSIS
    This Function uses the psPAS Module to get admin credentials for the WFM Network
 
.NOTES
    Name: Get-PASAccountList
    Author: Luke Hagar
    Version: 1.0
    DateCreated: 5/13/2021
 
.EXAMPLE
    $SelectedAccount = Get-PASAccountList
 
#>

    [CmdletBinding()]
    param (
        [string]
        $BaseURI = "https://myvault.wholefoods.com",
        [string]
        $Message = "Provide Credentials for CyberArk Password Vault",
        [string]
        $Prompt = 'Please Approve the Sign in Request on the Microsoft Authenticator app',
        [pscredential]
        $Credential
    )
    Add-Type -AssemblyName PresentationFramework
    Try { $Session = Get-PASSession }
    Catch { $Session = $null }
    if (!($Session)) {
        if (!($Credential)) {
            $User = Get-UserInfo
            $Credential = Get-Credential -UserName $User.UserPrincipalName -Message $Message
        }
        if ($null -ne $Credential) {
            [System.Windows.MessageBox]::Show($Prompt, 'CyberArk Connection Process', 'Ok') | Out-Null
            New-PASSession -Credential $Credential -BaseURI $BaseURI -type RADIUS
        } 
        else {
            Throw "No Credentials Provided"
        }
    }
    Try {
        $PASAccounts = Get-PASAccount | Select-Object *
        [System.Windows.MessageBox]::Show('Please select an account', 'CyberArk Connection Process', 'Ok') | Out-Null
        $SelectedAccount = ($PASAccounts | Out-GridView -OutputMode Single) | Sort-Object -Unique
        if ($null -ne $SelectedAccount) {
            Return $SelectedAccount
        }
        else {
            Throw "No Account selected"
        }
    }
    Catch { 
        Install-Dependencies
        Throw "Installed Dependencies, Please run command again"
    }
}