Private/Get-CurrentSubscriptionId.ps1
function Get-CurrentSubscriptionId { [CmdletBinding()] param( [Parameter(Mandatory = $false)] [string] $subscriptionId ) if ([string]::IsNullOrWhiteSpace($subscriptionId)) { Get-AzNetworkToolsToken try { $subscriptionId = (Get-AzContext).Subscription.Id.ToString() if ([string]::IsNullOrWhiteSpace($subscriptionId)) { throw "No subscription ID provided and no active Azure context found. Please connect to Azure using Connect-AzAccount or provide a subscription ID." } Write-Log "Using current subscription: $subscriptionId" } catch { throw "Error getting current subscription: $_. Please connect to Azure using Connect-AzAccount or provide a subscription ID." } } return $subscriptionId } |