Private/Get-SpecAzTableUri.ps1
function Get-SpecAzTableUri { <# .SYNOPSIS Generates a URI for accessing data in Azure Table Storage, optionally with filtering. .DESCRIPTION The Get-SpecAzTableUri function generates a Uniform Resource Identifier (URI) that can be used to access data in an Azure Table Storage. It is particularly useful for constructing URIs that include Shared Access Signatures (SAS) for secure access to your table data. This function can also include optional filtering parameters. .PARAMETER SAS The Shared Access Signature (SAS) token for authenticating and authorizing access to the Azure Table Storage. .PARAMETER StorageAccount The name of the Azure Storage Account where the table is located. .PARAMETER TableName The name of the target Azure Table. .PARAMETER Key An optional filtering key for the table data. .PARAMETER Value An optional filtering value associated with the filtering key. .PARAMETER CustomFilter An optional custom filter to apply to the URI. .PARAMETER AllData A switch parameter to indicate whether to generate a URI for accessing all data in the table. .EXAMPLE Generate a URI for accessing all data in the "MyTable" table: Get-SpecAzTableUri -SAS "your_sas_token" -StorageAccount "your_storage_account" -TableName "MyTable" .NOTES Author : owen.heaume Version : 1.0 It returns the following status codes: - 702: Indicates that a filtering key is provided, but the filtering value is missing. - 703: Indicates that a filtering value is provided, but the filtering key is missing. #> [cmdletbinding()] param( [parameter (mandatory = $true)] [string]$SAS, [parameter (mandatory = $true)] [string]$StorageAccount, [parameter (mandatory = $true)] [string]$TableName, [parameter (mandatory = $false)] [string]$Key, [parameter (mandatory = $false)] [string]$Value, [parameter (mandatory = $false)] [string]$CustomFilter, [Switch]$GetAllRows ) # $key has a value but $data does not! if ($key -and [string]::IsNullOrEmpty($value)) { Write-Warning "You have requested to return filtered data but the [value] parameter is missing" return 702 } # $key has a value but $data does not! if ($value -and [string]::IsNullOrEmpty($key)) { Write-Warning "You have requested to return filtered data but the [key] parameter is missing" return 703 } if ($key -and $value) { Write-Host "Creating filtered data URI" -ForegroundColor DarkGray # using a filter $filter = "`$filter=($key eq '$value')" return "https://$storageAccount.table.core.windows.net/$tablename$SAS&$filter" } elseif ($customfilter) { return "https://$storageAccount.table.core.windows.net/$tablename$SAS&`$filter=$CustomFilter" } elseif ($GetAllRows.IsPresent) { Write-Host "Creating all data URI" -ForegroundColor DarkGray # all table items return "https://$storageAccount.table.core.windows.net/$tablename$SAS" } } |