Private/Get-SpecCloudTable.ps1

Function Get-SpecCloudTable {
    <#
    .SYNOPSIS
    Retrieves a reference to a specific table in an Azure Storage account.
 
    .DESCRIPTION
    The Get-SpecCloudTable function retrieves a reference to a specific table in an Azure Storage account. It requires the Azure PowerShell module to be installed and authenticated.
 
    .PARAMETER tableStorageAccount
    Specifies the name of the Azure Storage account where the table is located. This parameter is mandatory.
 
    .PARAMETER tableResourceGroup
    Specifies the name of the resource group that contains the Azure Storage account. This parameter is mandatory.
 
    .PARAMETER TableName
    Specifies the name of the table to retrieve. This parameter is mandatory.
 
    .EXAMPLE
    Get-SpecCloudTable -tableStorageAccount "myStorageAccount" -tableResourceGroup "myResourceGroup" -TableName "myTable"
    Retrieves a reference to the "myTable" table in the "myStorageAccount" Azure Storage account located in the "myResourceGroup" resource group.
 
    .INPUTS
    None.
 
    .OUTPUTS
    System.Object
    Returns a reference to the CloudTable object representing the specified table.
 
    .NOTES
    This function requires the Azure PowerShell module to be installed and authenticated.
 
    Author: owen.heaume
    Version: 1.0
 
    .LINK
    Get-AzStorageAccount
    Get-AzStorageTable
    #>


    [CmdletBinding()]
    Param (
        [Parameter(Mandatory = $true)]
        [String]$tableStorageAccount,

        [Parameter(Mandatory = $true)]
        [String]$tableResourceGroup,

        [Parameter(Mandatory = $true)]
        [String]$TableName
    )

    try {
        $storageAccount = Get-AzStorageAccount -ResourceGroupName $tableresourceGroup -Name $tablestorageAccount -ErrorAction Stop
        $ctx = $storageAccount.Context
    } catch {
        Write-Warning "Unable to locate storage account: $tableStorageAccount. Are you sure it exists?"
        return 501
    }

    try {
        $storageTable = Get-AzStorageTable -Name $TableName -Context $ctx -ErrorAction Stop
        $cloudTable = $storageTable.CloudTable
    } catch {
        Write-Warning "Unable to locate table: $TableName. Are you sure it exists?"
        return 502
    }

    return $cloudTable
}