public/Get-AzToolsAutomationVariable.ps1

function Get-AzToolsAutomationVariable {
    <#
    .SYNOPSIS
        Get Azure Automation Account Variables
    .DESCRIPTION
        Get and/or export Azure Automation Account Variables
    .PARAMETER SelectContext
        Optional. Prompt to select the Azure context (tenant/subscription)
    .EXAMPLE
        Get-AzToolsAutomationVariable
 
        Returns all variables in the active Automation Account
    .LINK
        https://github.com/Skatterbrainz/aztools/tree/main/docs/Get-AzToolsAutomationVariable.md
    #>

    [CmdletBinding()]
    param(
        [parameter(Mandatory=$False,HelpMessage="Select Azure Context")]
            [switch]$SelectContext
    )
    if ($SelectContext) { Switch-AzToolsContext }
    if (!$global:AzToolsLastSubscription -or $SelectContext) { Select-AzToolsSubscription }
    if ($global:AzToolsLastSubscription) {
        Write-Verbose "Subscription: $($AzToolsLastSubscription.Id) - $($AzToolsLastSubscription.Name)"
        if (!$global:AzToolsLastResourceGroup -or $SelectContext) { Select-AzToolsResourceGroup }
        if ($global:AzToolsLastResourceGroup) {
            Write-Verbose "Resource group: $AzToolsLastResourceGroup"
            if (!$global:AzToolsLastAutomationAccount -or $SelectContext) { Select-AzToolsAutomationAccount }
            if ($global:AzToolsLastAutomationAccount) {
                $aaname = $global:AzToolsLastAutomationAccount.AutomationAccountName
                $rgname = $global:AzToolsLastResourceGroup.ResourceGroupName
                Write-Verbose "Account=$((Get-AzContext).Account) Subscription=$($AzToolsLastSubscription.Id) ResourceGroup=$($rgname) AutomationAccount=$($aaname)"
                $params = @{
                    ResourceGroupName = $rgname
                    AutomationAccountName = $aaname
                }
                $vars = Get-AzAutomationVariable @params | Sort-Object Name
                $vars
            } else {
                Write-Warning "Automation Account not yet selected"
            }
        } else {
            Write-Warning "Resource Group not yet selected"
        }
    } else {
        Write-Warning "Azure Subscription not yet selected"
    }
}