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-PASAdminCredential
    Author: Luke Hagar
    Version: 1.0
    DateCreated: 5/13/2021
 
.EXAMPLE
    $AdminCredential = Get-PASAdminCredential
 
#>

    Add-Type -AssemblyName PresentationFramework
    Try { $Session = Get-PASSession }
    Catch { $Session = $null }
    if (!($Session)) {
        $User = Get-UserInfo
        $PVCred = Get-Credential -UserName $User.UserPrincipalName -Message "Provide Credentials for CyberArk Password Vault"
        if ($null -ne $PVCred) {
            [System.Windows.MessageBox]::Show('Please Approve the Sign in Request on the Microsoft Authenticator app', 'CyberArk Connection Process', 'Ok') | Out-Null
            New-PASSession -Credential $PVCred -BaseURI "https://myvault.wholefoods.com" -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"
    }
}