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 Initial release 2.0 Clarify write-host statements and use write-error for efficient try \ catch block error trapping #> [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-Error '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-Error 'You have requested to return filtered data but the [key] parameter is missing' #return 703 } if ($key -and $value) { Write-Host 'Creating single-item data URI' -ForegroundColor DarkGray # using a filter $filter = "`$filter=($key eq '$value')" return "https://$storageAccount.table.core.windows.net/$tablename$SAS&$filter" } elseif ($customfilter) { Write-Host 'Creating custom filter data URI' -ForegroundColor DarkGray return "https://$storageAccount.table.core.windows.net/$tablename$SAS&`$filter=$CustomFilter" } elseif ($GetAllRows.IsPresent) { Write-Host "Creating 'get all' data URI" -ForegroundColor DarkGray # all table items return "https://$storageAccount.table.core.windows.net/$tablename$SAS" } } |