Public/Get-SpecAzTable.ps1
function Get-SpecAzTable { <# .SYNOPSIS Retrieves the entire contents of an Azure table. .DESCRIPTION This function retrieves all the records from an Azure table specified by the table name, resource group, and storage account. It uses the Azure PowerShell module (Az.Storage) to interact with the Azure Storage service. .PARAMETER TableName The name of the Azure table from which to retrieve the contents. This parameter is mandatory. .PARAMETER tableResourceGroup The resource group of the Azure Storage account containing the table. This parameter is mandatory. .PARAMETER tableStorageAccount The name of the Azure Storage account containing the table. This parameter is mandatory. .EXAMPLE Get-SPECAzTable -TableName "MyTable" -tableResourceGroup "MyResourceGroup" -tableStorageAccount "MyStorageAccount" This example retrieves all the records from the Azure table named "MyTable" in the storage account "MyStorageAccount" within the resource group "MyResourceGroup". .INPUTS This function accepts input through its parameters. .OUTPUTS This function outputs an array of table records retrieved from the specified Azure table. (system.array) .NOTES Author: owen.heaume Version: - 1.0 - 1.1 fix unicode issue #> [cmdletbinding()] param ( [Parameter(Mandatory = $true)] [string]$TableName, [Parameter(Mandatory = $true)] [string]$tableResourceGroup, [Parameter(Mandatory = $true)] [string]$tableStorageAccount ) Begin { # clean up leading and trailing whitespace in vars $TableName = $TableName.Trim() $tableResourceGroup = $tableResourceGroup.Trim() $tableStorageAccount = $tableStorageAccount.Trim() # Get Storage account context try { $storageAccount = Get-AzStorageAccount -ResourceGroupName $tableresourceGroup -Name $tablestorageAccount -ErrorAction Stop $ctx = $storageAccount.Context } catch { Write-Error "Unable to locate storage account: $tableStorageAccount. Are you sure it exists?" exit 500 } try { $storageTable = Get-AzStorageTable -Name $TableName -Context $ctx -ErrorAction Stop $cloudTable = $storageTable.CloudTable } catch { Write-Error "Unable to locate table: $TableName. Are you sure it exists?" exit 500 } } process { $tableresult = Get-AzTableRow -table $cloudTable if ($null -eq $tableresult) { Write-Warning "No records found in the table: $TableName" } Return $tableResult } } |