Public/Get-specSCLocationViaAzureTables.ps1
function Get-specSCLocationViaAzureTables { <# .SYNOPSIS Looks up one or more gateway IP addresses in an Azure Table and returns the matching location records. .DESCRIPTION The Get-specSCLocationViaAzureTables function queries an Azure Table using a SAS token and returns rows where the 'Gateway' field matches one or more provided IP addresses. The function supports pipeline input, including strings or objects with a 'Gateway' property. .PARAMETER AzureTable The name of the Azure Table to query. .PARAMETER StorageAccount The name of the Azure Storage Account where the table resides. .PARAMETER SASReadOnly A valid Shared Access Signature (SAS) token with read access to the Azure Table. .PARAMETER Gateway One or more gateway IP addresses to look up. Supports pipeline input and property binding. .INPUTS [string] You can pipe strings representing gateway IPs directly to this function. You can also pipe objects with a 'Gateway' property. .OUTPUTS [pscustomobject] Returns Azure Table entities matching the specified gateway IPs. .EXAMPLE Get-specSCLocationViaAzureTables -AzureTable 'Gateways' -StorageAccount 'myaccount' -SASReadOnly '?sv=...' -Gateway '1.2.3.4' Returns the matching row from the specified Azure Table. .EXAMPLE '2.3.4.5','4.5.6.7' | Get-specSCLocationViaAzureTables -AzureTable 'Gateways' -StorageAccount 'myaccount' -SASReadOnly '?sv=...' Pipes gateway IPs to the function and returns matches from the Azure Table. .EXAMPLE @([pscustomobject]@{Gateway='3.4.5.6'}, [pscustomobject]@{Gateway='8.8.8.8'}) | Get-specSCLocationViaAzureTables -AzureTable 'Gateways' -StorageAccount 'myaccount' -SASReadOnly '?sv=...' Pipes objects with a 'Gateway' property. Matching entries are returned; unmatched ones raise warnings. .NOTES Author: owen.heaume Version : 1.0 - Initial release #> [cmdletBinding()] param ( [Parameter(Mandatory = $true)] [string]$AzureTable, [Parameter(Mandatory = $true)] [string]$StorageAccount, [Parameter(Mandatory = $true)] [string]$SASReadOnly, [Parameter(Mandatory = $true, ValueFromPipeline = $true, valuefrompipelinebypropertyname = $true)] [string[]]$Gateway ) Begin { Write-Verbose 'In function: Get-specSCLocationViaAzureTables' $params = @{ tableName = $AzureTable StorageAccount = $StorageAccount GetAllRows = $true SASToken = $SASReadOnly } try { $allRows = Get-SpecAzTableRowUsingSAS @params -ea stop } catch { Write-Host "Error: $_ " -ForegroundColor DarkYellow } } Process { foreach ($gw in $Gateway) { $match = $allRows | ? { $_.Gateway -eq $gw } | select -First 1 if ($match) { Write-Verbose 'Gateway match found' $match } else { Write-Warning "No matching locations found for gateway: '$gw'" } } } End { Write-Verbose 'Out of function: Get-specSCLocationViaAzureTables' } } |