Public/Get-PASAdminCredential.ps1

Function Get-PASAdminCredential {
    <#
.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
 
#>

    Try {
        $User = Get-User
        $PVCred = Get-Credential -UserName $User.UserPrincipalName -Message "Provide Credentials for CyberArk Password Vault"
        if ($null -ne $PVCred) {
            $wshell = New-Object -ComObject Wscript.Shell
            $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
            $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) {
                $Username = $SelectedAccount.userName 
                $Password = ($SelectedAccount | Get-PASAccountPassword).ToSecureString()
                $AdminCredential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $Username, $Password
                Return $AdminCredential
            }
            else {
                Throw "No Account selected"
            }
        }
        else {
            Throw "No Credentials Provided"
        }
    }
    Catch { 
        Install-Dependencies
        Throw "Installed Dependencies, Please run command again"
    }
}