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
 
#>

    Begin {
        $wshell = New-Object -ComObject Wscript.Shell
        Try { Get-PASSession }
        Catch {
            Try {
                $User = Get-User
                $PVCred = Get-Credential -UserName $User.UserPrincipalName -Message "Provide Credentials for CyberArk Password Vault"
                if ($null -ne $PVCred) {
                    $wshell.Popup("Please Approve the Sign in Request on the Microsoft Authenticator app", 0, "Done", 0x1) | Out-Null
                    New-PASSession -Credential $PVCred -BaseURI https://myvault.wholefoods.com -type RADIUS
                } 
                else {
                    Throw "No Credentials Provided"
                }
            }
            Catch { 
                Install-Dependencies
                Throw "Installed Dependencies, Please run command again"
            }
        }
    }
    Process {
        $PASAccounts = Get-PASAccount
        $wshell.Popup("Please select the Admin account", 0, "Done", 0x1) | Out-Null
        $SelectedAccount = $PASAccounts | Out-GridView -OutputMode Single
        if ($null -ne $SelectedAccount) {
            Write-Output $SelectedAccount
            Return $SelectedAccount
        }
        else {
            Throw "No Account selected"
        }
    }
    End {}
}